// Java program to read character using Scanner // class import java.util.Scanner; public class ScannerDemo1 { public static void main(String [] args){ Scanner sc = new Scanner(System.in); char c = sc.next().charAt(1); // here this is the indexing of the element to take // System.out.println("c = "+c); } } //Input :ge //Oriented Language? Using predefined class name as Class or Variable name in Java Java.util.zip.InflaterOutputStream class in Java Scanner and nextChar() in Java Read Discuss Courses Practice Scanner class in Java supports nextInt(), nextLong(), nextDouble() etc. But there is no nextChar() (See this for examples) To read a char, we use next().charAt(0). next() function returns the next token/word in the input as a string and charAt(0) function returns the first character in that string, the number 0 in the function in CharAt(NUMBER) represents the index of the single word of the string taken input, and set that index character to the char variable. // Java program to read character using Scanner // class import java.util.Scanner; public class ScannerDemo1 { public static void main(String [] args){ Scanner sc = new Scanner(System.in); char c = sc.next().charAt(1); // here this is the indexing of the element to take // System.out.println("c = "+c); } } //Input :ge //Output :c = e