Java examples for Language Basics:int
A Class Whose readChar() Method Reads One Character from the Standard Input
import java.io.IOException; public class Main { public static void main(String[] args) { System.out.print("Enter some text and press Enter key: "); char c = readChar(); System.out.println("First character you entered is: " + c); }/*from ww w. j a v a 2 s. co m*/ public static char readChar() { char c = '\u0000'; int input = 0; try { input = System.in.read(); if (input != -1) { c = (char)input; } } catch (IOException e) { System.out.print("IOException occurred while reading input."); } return c; } }