you should also be careful that you understand the methods that you call. For example, the API for read states that it: Reads the next byte of data from the input stream.
Binary streams are different from character streams. If you type 123, System.in.read() will not return 123, but typically 49, the ASCII code value for the character '1'.
There is no emoticon for what I am feeling!
posted 12 years ago
Mr Albrechtsen's reply is of course very appropriate, for the benefit of Mr De Maio, I comment my previous given code:
InputStream (System.in)reads bytes, so less suitable for text and numbers, we need something to read characters: a Reader (in my code a bufferedReader to read as efficiently as possible) An InputStreamReader is a bridge from byte streams (read be InputStream)to character streams(read by Reader)
Like a plumber, we fix the pipes one after the other: InputStream is = System.in;//read bytes InputStreamReader isr = new InputStreamReader(is);//bytes to characters BufferedReader br = new BufferedReader(isr);//read and store characters
the last thing "reads a line of text", and stops when it encounters <ENTER> Then we try to extract of double from what is read...