Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading input from keyboard 2

Status
Not open for further replies.

madhugiri

Programmer
Feb 7, 2000
1
0
0
US
how do i read an interger value from the keyboard ?<br>

 
Read a string from the standard input (System.in), then parse it to integer (Integer.parseInt()).<br>
<br>
Good luck. Bye, Otto.<br>

 
There is also a class for keyboardInput that has a method readInt();<br>
<br>
Tanya
 
Not!<br>
The readInt() always reads four bytes (32 bit). If you type<br>
1234, the result will be $31*65536+$32*256+$33*16+$34 (ASCII code*2^...), and not 1234. The readInt() is suitable only DataInputStream-s (and descendants).<br>
<br>
Bye, Otto.<br>

 
HI,<br>
Why not to read a line from the keyboard<br>
<br>
BufferedReader br = new BufferedReader( new InputStreamReader( System.in));<br>
String str = br.readLine() ;<br>
<br>
and then <br>
<br>
int value = Integer.parseInt( str ) ;<br>
<br>
Hope it will help<br>
<br>
Regards.<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top