Hi,
I was trying to run my program after compiling but after I key in an integer, the following error came out :
Program code
import java.io.*;
public class Analysis
{
public static void main( String args[] ) throws IOException
{
int counter, total1, total2, result;
total1 = 0;
total2 = 0;
counter = 1;
while ( counter <= 10 )
{
System.out.print( "Enter result: " );
System.out.flush();
result = System.in.read();
if ( result == '1' )
total1 = total1 + 1;
else if ( result == '2' )
total2 = total2 + 1;
System.in.skip( 1 );
counter = counter + 1;
}
System.out.println( "Pass " + total1 );
System.out.println( "Fail " + total2 );
}
}
Error
Enter result: 1
Enter result: Exception in thread "main" java.io.IOException: The handle is invalid
at java.io.FileInputStream.skip(Native Method)
at java.io.BufferedInputStream.skip(BufferedInputStream.java:313)
at Analysis.main(Analysis.java, Compiled Code)
I was compiling using "javac Analysis.java".
Thanks !!
Regards,
Spec
I was trying to run my program after compiling but after I key in an integer, the following error came out :
Program code
import java.io.*;
public class Analysis
{
public static void main( String args[] ) throws IOException
{
int counter, total1, total2, result;
total1 = 0;
total2 = 0;
counter = 1;
while ( counter <= 10 )
{
System.out.print( "Enter result: " );
System.out.flush();
result = System.in.read();
if ( result == '1' )
total1 = total1 + 1;
else if ( result == '2' )
total2 = total2 + 1;
System.in.skip( 1 );
counter = counter + 1;
}
System.out.println( "Pass " + total1 );
System.out.println( "Fail " + total2 );
}
}
Error
Enter result: 1
Enter result: Exception in thread "main" java.io.IOException: The handle is invalid
at java.io.FileInputStream.skip(Native Method)
at java.io.BufferedInputStream.skip(BufferedInputStream.java:313)
at Analysis.main(Analysis.java, Compiled Code)
I was compiling using "javac Analysis.java".
Thanks !!
Regards,
Spec