Example - Read an Int From the Keyboard


import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

public class IntIO
{
    public static void main(String[] args)
    {
        InputStreamReader convert = new InputStreamReader(System.in);
        BufferedReader stdin = new BufferedReader(convert);
        String instr;

        try
        {
            System.out.println("Type an int ");
            instr = stdin.readLine();
            int num = Integer.parseInt(instr);
            System.out.println("The int read was: " + num);
            num = num * 2;
            System.out.println("After the computation, the result is: " + num);
        }
        catch(IOException e) {}
    }

}

Output:

Type an int 
124
The int read was: 124
After the computation, the result is: 248


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page