0

I am trying to insert a char value from scanner class. I tried it in the following way.

Scanner sc = new Scanner(System.in);
character = sc.nextChar();

It's not working Since my next method only take char value. I tried it by using sc.charAt(0). it worked. Is there another way to try.

Sharon Ben Asher
  • 12,476
  • 5
  • 25
  • 42
  • 3
    Possible duplicate of [Take a char input from the Scanner](https://stackoverflow.com/questions/13942701/take-a-char-input-from-the-scanner) – xingbin Jul 08 '18 at 07:17

1 Answers1

0

Use the following

char c= sc.nextLine().charAt(0);

Here, you are reading a string and take the first character of it.