wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Accepting Digits through Keyboard Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Accepting Digits through Keyboard" Watch "Accepting Digits through Keyboard" New topic
Author

Accepting Digits through Keyboard

Suvojit Chakraborty
Ranch Hand

Joined: Nov 10, 2009
Posts: 62
    
    1
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

Joined: Oct 01, 2001
Posts: 2833
    
  11

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accepting Digits through Keyboard
 
Similar Threads
char literal
How to show arabic and arabic in a JTextBox when user enter the numbers?
iPad
scanning items into database for online shopping site
eek, help!