Getting user input | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Getting user input

How can a user input only one character.

30th Mar 2019, 4:54 AM
Mesut Awahab
Mesut Awahab - avatar
1 Answer
+ 3
You can get the next word and take only the first character as input. Scanner sc = new Scanner(System.in); char c = sc.next().charAt(0); or, you can use the same technique with .next(), and reject the input if .length() is found to exceed 1.
30th Mar 2019, 5:00 AM
Hatsy Rei
Hatsy Rei - avatar