• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accepting Digits through Keyboard

 
Suvojit Chakraborty
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I have a small question:
Can any one tel me how can I accept digits through keyboard.
I tried using read(int) but it returns some absurd value.

Thanks for answering
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know of a typical read(int) method. Reader has read(), which reads a character and returns its integer value, and InputStream() has read(), which does the same for a byte. If you are using one of those, the "absurd value" you see is probably the ASCII value of the character for the digit. 48 for 0, 49 for 1, etc. You will need to convert from the ASCII value to the integer value. Also, if you ever need to convert a multiple digit number to an integer, take a look at the Java API Scanner class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic