University of Toronto - Fall 2000
Department of Computer Science

Week 3 - Input

Reading Input

Here's a complete program that reads in an integer, stores it in variable i, and then prints it out again.

// EchoInt: program to read and print one integer.

import java.io.*;

public class EchoInt {

	public static void main (String[] args) throws IOException {

		BufferedReader in = new BufferedReader
				(new InputStreamReader (System.in));

		System.out.println ("Enter an integer: ");
		String line = in.readLine();
		int i = Integer.parseInt(line);
		System.out.println("You entered " + i);
	}
}