FileDocCategorySizeDatePackage
ReadStdinInt.javaAPI DocExample672Sun Feb 08 17:57:30 GMT 2004None

ReadStdinInt

public class ReadStdinInt extends Object
Read an int from Standard Input
author
Ian F. Darwin, http://www.darwinsys.com/
version
$Id: ReadStdinInt.java,v 1.2 2004/02/08 23:57:29 ian Exp $

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] ap)

		String line = null;
		int val = 0;
		try {
			BufferedReader is = new BufferedReader(
				new InputStreamReader(System.in));
			line = is.readLine();
			val = Integer.parseInt(line);
		} catch (NumberFormatException ex) {
			System.err.println("Not a valid number: " + line);
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}
		System.out.println("I read this number: " + val);