| Author |
System.in.read()
|
fred bates
Greenhorn
Joined: Jan 25, 2002
Posts: 1
|
|
When I use System.in.read to re trieve int values from the keyboard I seem to be getting the ASCII value of the integer, and can't cast it to an int. What can I do to fix this problem?
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18652
|
|
|
Yes, you're getting ASCII values (or rather, ISO-8859-1 values, most likely) of the characters entered by the user. You can convert the user input into a single String by wrapping System.in in an InputStreamReader, and wrapping that in a BufferedReader (which has a readLine() method). Then you can use Integer.parseInt(String) to convert the String to an int.
|
"I'm not back." - Bill Harding, Twister
|
 |
 |
|
|
subject: System.in.read()
|
|
|