/*
Quick and dirty samples of System.in NOTE: You may have to position the cursor in the
correct spot in the console window for
the input to work correctly!
*/
import java.io.*;
public class SystemInRead {
public static void main(String args[]) throws IOException {
char ch;
System.out.print("Type a character: ");
// read() reads a byte of data into an int
ch = (char)System.in.read();
System.out.println("You typed <" + ch + "> ascii: " + (int)ch);
// skip over the CR/LF to set up for the next input
System.in.skip(2);
// create a BufferedReader from the input stream 'in'
BufferedReader stdin =
new BufferedReader(
new InputStreamReader(System.in));
System.out.print("Enter a line:");
String theInput = stdin.readLine();
System.out.println(theInput);
int i;
// setup to catch the exception the parseInt method may throw
try {
i = Integer.parseInt(theInput);
System.out.println("Thank you, # is: " + i);
}
catch (NumberFormatException e) {
System.out.println("problem with that number");
}
}
}