首页 > 代码库 > 判断成绩
判断成绩
代码如下:
package ClassDemo; public class TestVoidMethod {
public static void main(String[] args) {
//判断成绩的方法
System.out.println("The grade is: " + printGrade(96));
System.out.println("The grade is: " + printGrade(86));
System.out.println("The grade is: " + printGrade(76));
System.out.println("The grade is: " + printGrade(196));
}
//判断成绩的方法
private static char printGrade(int score) {
if (score < 0 || score > 100) {
System.out.println("输入成绩不合法");
return ‘ ‘;
}
if (score >= 90) {
return ‘A‘;
} else if (score >= 80) {
return ‘B‘;
} else if (score >= 70) {
return ‘C‘;
} else if (score >= 60) {
return ‘D‘;
} else {
return ‘E‘;
}
}
}
package ClassDemo;
public class TestVoidMethod {
public static void main(String[] args) {
int score1 = 96;
//判断成绩的方法
printGrade(score1);
}
//判断成绩的方法
private static void printGrade(int score) {
if (score < 0 || score > 100) {
System.out.println("输入成绩不合法");
return;
}
switch (score / 10) {
case 10:
case 9:
System.out.println("优秀");
case 8:
System.out.println("良好");
break;
case 7:
System.out.println("中");
break;
case 6:
System.out.println("合格");
break;
default:
System.out.println("不合格");
break;
}
return;
}
}
判断成绩