Following is the code, I have written to get two inputs from user. But when I run the program, It takes only one input and generate other by itself and calculate the wrong v
Read() method.
Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
from http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#read%28%29.
So use scanner for this.
And according to your question Why is it not asking for second input? Reason is read() method wait for input source once it gets the input it takes the byte by byte from that input source. For ex:
inChar = System.in.read();
i = System.in.read();
i1 = System.in.read();
System.out.print("You entered ");
System.out.println(inChar);
System.out.println(i);
System.out.println(i1);
you enter abcas input then you will get
Enter a Character:
abc
You entered 97
98
99
as out put which is byte values of a,b and c.
Explanation: input abc
byte array
+--------------------+
| 97 | 98 | 99 | other byte value for **Enter**
+--------------------+
first System.in.read() will get first index of array, second one will get second and so on.