I am trying to find a way to take a char
input from the keyboard.
I tried using:
Scanner reader = new Scanner(System.in);
char c = reade
There is no API method to get a character from the Scanner. You should get the String using scanner.next()
and invoke String.charAt(0)
method on the returned String.
Scanner reader = new Scanner(System.in);
char c = reader.next().charAt(0);
Just to be safe with whitespaces you could also first call trim()
on the string to remove any whitespaces.
Scanner reader = new Scanner(System.in);
char c = reader.next().trim().charAt(0);