它一直说第一个表达的非法开始,但我不知道我做错了什么
double total_score = quiz_average * 20% + assignment_average*20% + exam_average * 60%;
if (total_score <= 100 && total_score >= 90) {
System.out.println("A");
} else if (total_score <= 89.99 && total_score >= 80) {
System.out.println("B");
} else if (total_score <= 79.99 && total_score >= 70) {
System.out.println("C");
} else if (total_score <= 69.99 && total_score >= 60) {
System.out.println("D");
} else if (total_score <= 59.99 && total_score >= 0) {
System.out.println("F");
}
在行中:
double total_score = quiz_average * 20% + assignment_average*20% + exam_average * 60%;
您正在使用20%
和60%
。这些不是有效的常量。%
实际上是模运算符(请参阅乘法下(,这不是您想要的。而是使用.2
和.6
来获取百分比:
double total_sore = (quiz_average * 0.2) + (assignment_average * 0.2) + (exam_average * 0.6);