View Single Post
  #1 (permalink)  
Old 03-19-2008, 01:24 PM
kantze kantze is offline
Member
 
Join Date: Mar 2008
Posts: 1
kantze is on a distinguished road
System.in.read(); strange error!
Hi, i'm new to java. I'm trying to read an integer and to print it.

Here is what i've done so far...
Code:
import java.io.IOException; public class helloworld { public static void main(String[] args) throws IOException { int a = System.in.read(); System.out.println(a); } }
The problem is, that if for example i write 3 the console prints 51 ( its' ansi representation, i guess??)

I must write this
Code:
System.out.println( (char)a);
to make it work.

But, when I do this
Code:
import java.io.IOException; public class helloworld { public static void main(String[] args) throws IOException { int a = 3; System.out.println(a); } }
everything is printed right.

Could anyone tell me what's happening??
Reply With Quote
Sponsored Links