Example - Read a Double From the Keyboard


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

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

        try
        {
            System.out.println("Type a double ");
            instr = stdin.readLine();
            double dnum = new Double(instr).doubleValue();
            System.out.println("The double read was: " + dnum);
            dnum = dnum * 2;
            System.out.println("After the computation, the result is: " + dnum);
        }
        catch(IOException e) {}
    }

}

Output:
Type a double 
1.414
The double read was: 1.414
After the computation, the result is: 2.828


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