• Post Reply Bookmark Topic Watch Topic
  • New Topic

while using System.in read()?  RSS feed

 
Anto Telvin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

i was trying to use System.in.read(). i entered a number 23 and i am just printing it .i got 50 as output .what is happening here?
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to read what the parameters and return values of InputStream.html#read() are. It says "int".

Also that method reads one byte at a time; if you enter 23 it is actually reading 2. Go and find an ASCII table (or the Unicode "U0000.pdf" file) and find the value for "2". I think you might find it is 0x32, which comes out in decimal as 50 . . . QED
 
Anto Telvin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!