// switch 多分支语句
public static String evaluateGradeWithSwitch(int score) {
// 将分数映射到类别编号
int gradeCategory;
if (score >= 100) {
gradeCategory = 6;
} else if (score >= 90) {
gradeCategory = 5;
} else if (score >= 80) {
gradeCategory = 4;
} else if (score >= 70) {
gradeCategory = 3;
} else if (score >= 60) {
gradeCategory = 2;
} else {
gradeCategory = 1;
}
// 使用switch语句判断类别编号,并返回对应的评价
switch (gradeCategory) {
case 6:
return "学霸";
case 5:
return "优秀";
case 4:
return "良好";
case 3:
return "中等";
case 2:
return "及格";
default:
return "不及格";
}
}