2 回答
TA贡献1835条经验 获得超7个赞
其因为无限循环 eclipse 显示该错误。我假设您想检查输入等级是否为有效条目。假设输入等级应该在 0 到 100 之间,更改while ( grade >= 0 )
为if ( grade >= 0 && grade <= 100 )
.
TA贡献1818条经验 获得超7个赞
我不是 Java 人,但这应该可行。我可以提供这样的解决方案。
import java.util.Scanner;
public class ClassStudent {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int A=0;
int F=0;
int total=0;
int counter=0;
double Av12;
int pass=0;
int fail=0;
int grade;
do {
System.out.println("enter grades or enter -1 to exit : ");
grade=input.nextInt();
if (grade>90 && grade<=100) {
A++;
pass++;
}
if (grade>0 && grade<=59) {
F++;
fail++;
}
total=total+grade;
counter++;
} while(grade>=0);
System.out.println("the total is "+total);
Av12=(double)total/counter;
System.out.printf("the averge is %.2f %n ",Av12);
System.out.printf("num of A is %d %n and F is %d%n and fail is %d%n and pass is %d%n ",A,F,fail,pass);
}
}
添加回答
举报