/*
Read character from console using InputStream
This example shows how to read a character from console window.
This example also shows how to read user entered data from console window
using System.in
*/
import java.io.IOException;
public class ReadCharFromConsoleExample {
public static void main(String[] args) {
/*
* To read a character from console use,
* read method of InputStream class variable System.in
* which defined as static variable.
*/
int iChar = 0;
System.out.println("Read user input character example");
try
{
System.out.println("Enter a character to continue");
iChar = System.in.read();
System.out.println("Char entered was : " + (char)iChar);
}
catch(IOException e)
{
System.out.println("Error while reading : " + e);
}
}
}
/*
Typical output would be
Read user input character example
Enter a character to continue
a
Char entered was : a
*/
Bookmark/Search this post with:
Post new comment