Which methods are used to take a character from keyboard in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Which methods are used to take a character from keyboard in java

I am using char Y=sc.nextLine(); or char Y=sc.next(); but it is error https://code.sololearn.com/cSioi3651m88/?ref=app

28th Dec 2017, 12:49 PM
Ramshek Rana
Ramshek Rana - avatar
4 Answers
+ 9
Use the following line: char Y = sc.next().charAt(0); It'll save the first character of the string as the char variable.
28th Dec 2017, 1:18 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 2
lot of thanks Shamima
28th Dec 2017, 1:23 PM
Ramshek Rana
Ramshek Rana - avatar
+ 1
did you included the Scanner class??
28th Dec 2017, 1:00 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
0
yes
28th Dec 2017, 1:04 PM
Ramshek Rana
Ramshek Rana - avatar