Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is my code to take ‘char’ input from the keyboard: 

Scanner reader = new Scanner(System.in);

char c = reader.nextChar();

But this method doesn’t exist. Can anyone tell me how to explicitly take a char input from the Scanner? 

1 Answer

0 votes
by (19.7k points)

Solution: 

  1. To take first character: 

char c = reader.next().charAt(0);

  1. To take exactly one character : 

char c = reader.findInLine(".").charAt(0);

  1. To take strictly one character:

char c = reader.next(".").charAt(0);

Interested in Java? Check out this Java Certification by Intellipaat.  

Related questions

0 votes
1 answer
asked Mar 20, 2021 in Java by Jake (7k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 11, 2020 in Python by ashely (50.2k points)
0 votes
1 answer

Browse Categories

...