我需要使用我的代码行中嵌套的“ if”来找到测试平均值和总体平均值的帮助。当我尝试将其放入嵌套的IF语句中时,它不会运行。
System.out.print("Enter Test Scores : ");
for(i=0; i<7; i++)
{
myList[i] = scan.nextInt();
sum = sum + myList[i];
}
for (i = 0; i < 6; i++) {
totalPts += myList[i];
}
testAvg = totalPts/6;
finalExam = myList[myList.length-1];
finalAvg = (testAvg *.6) + (finalExam *.4);
System.out.println("Final Avergae: " + finalAvg);
System.out.println("Here are you grades: ");
for (i = 0; i < 7; i++) {
System.out.println(myList[i]);
}
System.out.print("Your Grade is ");
if (finalAvg>= (double)90)
{
System.out.print("A");
}
else if(finalAvg >= 80 && finalAvg < (double)90)
{
System.out.print("B");
}
else if(finalAvg >= 70 && finalAvg < (double)80)
{
System.out.print("C");
}
else if(finalAvg >= 60 && finalAvg > (double)70)
{
System.out.print("D");
}
else
{
System.out.print("F");
}
}
}
答案 0 :(得分:0)
你是这个意思吗?
if (finalAvg >= 90) {
System.out.print("A");
} else {
if (finalAvg >= 80) {
System.out.print("B");
} else {
if (finalAvg >= 70) {
System.out.print("C");
} else {
if (finalAvg >= 60) {
System.out.print("D");
} else {
System.out.print("F");
}
}
}
}