Take a char input from the Scanner

前端 未结 22 2285
[愿得一人]
[愿得一人] 2020-11-22 05:16

I am trying to find a way to take a char input from the keyboard.

I tried using:

Scanner reader = new Scanner(System.in);
char c = reade         


        
22条回答
  •  旧时难觅i
    2020-11-22 06:03

    The best way to take input of a character in Scanner class is:

    Scanner sca=new Scanner(System.in);
    System.out.println("enter a character");
    char ch=sca.next().charAt(0);
    

提交回复
热议问题