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 = reader.nextChar();
This method doesn't exist.
I tried taking c
as a String
. Yet, it would not always work in every case, since the other method I am calling from my method requires a char
as an input. Therefore I have to find a way to explicitly take a char as an input.
Any help?
Setup scanner:
After this
reader.next()
will return a single-character string.Try this: char c=S.nextLine().charAt(0);
Try this
Just use...
That's it...
You should use your custom input reader for faster results instead of extracting first character from reading String. Link for Custom ScanReader and explanation: https://gist.github.com/nik1010/5a90fa43399c539bb817069a14c3c5a8
Code for scanning Char :