can't read int value

import java.io.*;

class binary

{

publicstaticvoid main(String args[])

{

BufferedReader br;

int ch=0;

br =new BufferedReader(new InputStreamReader(System.in));

System.out.println("enter value");

try

{

ch = (int)br.read();

}

catch(IOException e)

{

System.out.println("Exception Caught");

}

System.out.println("the value entered is :" + ch);

}

}

the read method used above reads an character and returns it integer value and if we want to read an integer value how to do so, i tried it in the above code but it doesn't work

is there any specific function for reading int values or we need to use the ByteStream classes instead of the Character ones

plz reply

[1446 byte] By [gaurav_xmla] at [2007-11-27 2:35:42]
# 1
System.in is an InputStream and has hence this method is applicable:read()// Reads the next byte of data from the input stream.
BIJ001a at 2007-7-12 2:54:17 > top of Java-index,Java Essentials,New To Java...
# 2
but i didn't work i simply did ch = (int)System.in.read();it doesn't return the int value rather some garbage value
gaurav_xmla at 2007-7-12 2:54:17 > top of Java-index,Java Essentials,New To Java...
# 3
If you use a reader and read some textual String, you can concert it into an int like this:String s= "123";int i = Integer.parseInt(s);
BIJ001a at 2007-7-12 2:54:17 > top of Java-index,Java Essentials,New To Java...
# 4
thanks it worked i read my number using the readLine() method as a String and then converted it back to an int valuebut is there no method by which i could read values as int from the console n not have to do the conversion part.
gaurav_xmla at 2007-7-12 2:54:17 > top of Java-index,Java Essentials,New To Java...
# 5

> thanks it worked

> i read my number using the readLine() method as a

> String and then converted it back to an int value

> ut is there no method by which i could read values as

> int from the console n not have to do the conversion

> part.

plz heply guys

gaurav_xmla at 2007-7-12 2:54:17 > top of Java-index,Java Essentials,New To Java...
# 6
Read the API for Scanner.
masijade.a at 2007-7-12 2:54:17 > top of Java-index,Java Essentials,New To Java...