• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java JDK2 RUN problem ...

Spectrum

Member
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( &quot;Enter result: &quot; );
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( &quot;Pass &quot; + total1 );
System.out.println( &quot;Fail &quot; + total2 );
}
}


Error

Enter result: 1
Enter result: Exception in thread &quot;main&quot; 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 &quot;javac Analysis.java&quot;.
Thanks !!

Regards,
Spec

 
Back
Top