public class average1{
public static void main(String args[])throws IOException{
int counter,grade,total;
double average;
total=0;
counter=0;
System.out.print("Enter lettle grade,z to end: ");
System.out.flush();
grade=System.in.read();
while (grade!='z'){
if (grade=='A')
total=total+5;
else if (grade=='B')
total=total+4;
else if (grade=='C')
total=total+3;
else if (grade=='D')
total=total+2;
else if (grade=='F')
total=total+0;
System.in.skip(1);
counter=counter+1;
System.out.print("Enter lettle grade,z to end: ");
System.out.flush();
grade=System.in.read();
}
if (counter!=0){
average=(double)total/counter;
System.out.println("class average is:"+average);
}
else
System.out.println("No grade were entered");
}
}
上面的程序编译都没出问题,但运行后输入 A 后按回车键却出现下面的东西
Enter letter grade,z to end:Exception in thread"main" java.io.IOException:句柄无效
at java.io.FileInputStream.skip<Native Method>
at.java.io.BufferedInputStream.skip(BufferedInputStream.java:305>
at average1.main<average1.java:22)
请高手帮我解决这个问题啊