+ 4
How to input a character value in java ?
when I am trying to input a character through Scanner... by using next(); function.... it is giving a error regarding conversion... when I did same one through blue J ...it ran absolutely correct...need some solution plz https://code.sololearn.com/c7XSb6qLS02i/?ref=app
3 Respuestas
+ 5
Just an explanation:
sc.next() Grabs the first word up to a white space. So, it will be a string, not a character. You would need to convert it to character, or just take the first character from the word. (See @Dayve's) code for that.
+ 21
// There's a way:
ch = sc.next().charAt(0);
EDIT -- "For explaination, refer to @Rrestoring faith's answer!"
+ 3
OK...got it.👍.. thank u everyone