This is the code thats causing the problem. It is prety straightforward.
import java.io.*;
public class Mys
{
public static void main( String args[] ) throws IOException
{
int x;
System.out.print( "Enter value for x: ");
System.out.flush();
x = System.in.read();
System.in.skip(1);
System.out.println( "x = " + x );
}
}
03-26-2000, 12:09 AM
Paul Clapham
Re: Code with the error
Yes, that's what's happening. System.in does return an int but the Java
documentation says: Reads the next byte of data from the input stream. It's
reading a byte and casting it to an int. Try running the program and
entering things that aren't digits. It won't throw an error, it will just
give you the Unicode value of the characters you type.
How to get what you want? Here's some code that works (Java doesn't make it
easy to get input from the console!)
char ca[] = {(char)x};
int i = Integer.parseInt(new String(ca));
System.out.println( "x = " + i );
anu <arunaa@hotmail.com> wrote in message news:38db9e87$1@news.devx.com...
>
> This is the code thats causing the problem. It is prety straightforward.
>
>
> import java.io.*;
>
> public class Mys
> {
> public static void main( String args[] ) throws IOException
> {
> int x;
>
> System.out.print( "Enter value for x: ");
> System.out.flush();
> x = System.in.read();
> System.in.skip(1);
>
>
> System.out.println( "x = " + x );
>
> }
>
> }