0
How to input a character in Java?
I want to use switch case with alphabets. So how do I get a user input of a single character using Scanner.
3 Réponses
+ 17
As with the Scanner class, this way :
char c = input.next(".").charAt(0);
or char c = input.next().charAt(0);
+ 17
You initiated the object but not the data type. This would take String as it's data type, not a char.
Char is not available as an input in the whole Scanner class, that's why we put a charAt(); after the input.
+ 1
sorry @Dayve...my code works for a single word not a character.