Take a char input from the Scanner

前端 未结 22 2812
[愿得一人]
[愿得一人] 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
    闹比i (楼主)
    2020-11-22 06:12

    You should use your custom input reader for faster results instead of extracting first character from reading String. Link for Custom ScanReader and explanation: https://gist.github.com/nik1010/5a90fa43399c539bb817069a14c3c5a8

    Code for scanning Char :

    BufferedInputStream br=new BufferedInputStream(System.in);
    char a= (char)br.read();
    

提交回复
热议问题