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
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();
// Use a BufferedReader to read characters from the console.
import java.io.*;
class BRRead {
public static void main(String args[]) throws IOException
{
char c;
BufferedReader br = new
BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter characters, 'q' to quit.");
// read characters
do {
c = (char) br.read();
System.out.println(c);
} while(c != 'q');
}
}
import java.io.*;
class abc // enter class name (here abc is class name)
{
public static void main(String arg[])
throws IOException // can also use Exception
{
BufferedReader z =
new BufferedReader(new InputStreamReader(System.in));
char ch = (char) z.read();
} // PSVM
} // class
Try this
Scanner scanner=new Scanner(System.in);
String s=scanner.next();
char c=s.charAt(0);