| Author |
couldn't get back integer value
|
Alvin chew
Ranch Hand
Joined: Jan 08, 2004
Posts: 834
|
|
hi , i have a problem which i couldn't get back integer user keyin input, anyone please guide me ... the result display 51 rather than user integer input tq
|
 |
Stefan Wagner
Ranch Hand
Joined: Jun 02, 2003
Posts: 1923
|
|
|
If you look at the docs, what does read() claim to return?
|
http://home.arcor.de/hirnstrom/bewerbung
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
Alvin, You mention that the output is 51, but you don't mention the input. I'll assume you input 3. Note that the character '3' is ASCII and Unicode character number 51. Does this hint give you an idea of what the read method might be returning? Note that the documentation mentioned by Stefan is located at http://java.sun.com/j2se/1.4.2/docs/api/ If it's not clear yet, the thing to understand is that the read method is returning the value of the input character, and that the value of the character '3' is 51, '4' is 52, etc. (A nice reference to have around at times is http://asciitable.com for such character information.) If you were to alter your final output to cast the input to a char, you might see what you were expecting in the first place. System.out.println("num: " + (char)a); Also, note that you might at times prefer to use a BufferedReader, which is capable of reading in an entire line of input as a String. [ March 31, 2004: Message edited by: Dirk Schreckmann ]
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Alvin chew
Ranch Hand
Joined: Jan 08, 2004
Posts: 834
|
|
|
yes, my input is 3 , all i want is to display 3 ....as mentioned by Dirk, it is ascii code ..fine , but how i get back 3 rather than 51 ? means how i convert ascii code to integer input that user keyin ?
|
 |
Alvin chew
Ranch Hand
Joined: Jan 08, 2004
Posts: 834
|
|
|
oh ...i get it ...thks dirk and stefan ....need to cast it to char ... i get
|
 |
Alvin chew
Ranch Hand
Joined: Jan 08, 2004
Posts: 834
|
|
sorry....problem again refer to program , if i wan variable "a" become non-ascii code number for processing purpose as parameter or value for addtional subtraction and so like , what should i do ? is that possible i can parse it to NON-ascii number "3" in this case ? tq
|
 |
 |
|
|
subject: couldn't get back integer value
|
|
|