Results 1 to 3 of 3
Thread: System.in.read(); strange error!
- 03-19-2008, 12:24 PM #1
Member
- Join Date
- Mar 2008
- Posts
- 1
- Rep Power
- 0
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...
The problem is, that if for example i write 3 the console prints 51 ( its' ansi representation, i guess??)Java 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); } }
I must write thisto make it work.Java Code:System.out.println( (char)a);
But, when I do this
everything is printed right.Java Code:import java.io.IOException; public class helloworld { public static void main(String[] args) throws IOException { int a = 3; System.out.println(a); } }
Could anyone tell me what's happening??
- 03-19-2008, 01:41 PM #2
Member
- Join Date
- Mar 2008
- Posts
- 3
- Rep Power
- 0
System.in.read() method reads the next byte of data from inputstream. The Value byte is returned as an int in the range 0 to 255. If no byte is available the value -1 is returned.
But in the code fragment int a=3; we are assinging integer value to position allocated for integer variable a. So it creates no problem.
hope is usefull,
thank you
- 03-19-2008, 01:44 PM #3
Member
- Join Date
- Mar 2008
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Need help on a strange file access prob
By squad in forum Advanced JavaReplies: 0Last Post: 03-21-2008, 10:55 AM -
How to read the following
By rrp in forum New To JavaReplies: 0Last Post: 12-03-2007, 06:16 PM -
Strange error message "Source not found"
By ppayal in forum EclipseReplies: 0Last Post: 11-25-2007, 06:19 PM -
ERROR: Java(TM) failes to apply changes to your system
By coco in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:40 AM -
read txt file
By sureshsri1981 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 08-05-2007, 03:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks