+ 3

I have problem with "Scanner" in Java.

Hi guys! I have problem with "Scanner" in Java I need the program to request user input and then check what the user entered. If it is the letter "Y", it displays "all ok". But when I enter "Y" the program thinks that I entered not "Y" https://code.sololearn.com/cfq7i5MZS3tb/?ref=app How can I fix the problem?

15th Jun 2019, 1:25 PM
Сергей Серёгин
Сергей Серёгин - avatar
3 ответов
+ 4
Hey bro you should convert your type of your variable varVar into char type.because user enter only single letter Y and in java single letter is char.
15th Jun 2019, 1:31 PM
Maninder $ingh
Maninder $ingh - avatar
+ 3
Maninder $ingh But Scanner.nextLine() and Scanner.next() expects a String. The Scanner has no method for char.
15th Jun 2019, 2:21 PM
Denise Roßberg
Denise Roßberg - avatar