The answer is seen below:
Here is the complete program.
The variable stdin
is this program's name for a BufferedReader
object.
A BufferedReader
buffers characters that come from an
InputStreamReader
which is connected
to the raw input stream System.in
.
import java.io.*; class InputToDouble { public static void main (String[] args) throws IOException { String charData; double value; BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in)); System.out.println("Enter a double:"); charData = stdin.readLine(); value = Double.parseDouble( charData ) ; System.out.println("value: " + value +" twice value: " + 2*value ); } }
There are lots of things to understand in this program. Don't be afraid to go through these notes again.