用Scanner的nextInt()方法输入一个百分制成绩,输出成绩等级A、B、C、D、E,其中90~100分为A,80~89分为B,70~79分为C,60~69分为D ,60分以下分为E。使用switch语句
时间: 2023-05-27 11:07:12 浏览: 138
示例代码如下:
```
import java.util.Scanner;
public class ScoreGrade {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入百分制成绩:");
int score = scanner.nextInt();
scanner.close();
// 判断成绩等级
String grade;
switch (score / 10) {
case 10:
case 9:
grade = "A";
break;
case 8:
grade = "B";
break;
case 7:
grade = "C";
break;
case 6:
grade = "D";
break;
default:
grade = "E";
break;
}
System.out.println("成绩等级为:" + grade);
}
}
```
运行结果示例:
```
请输入百分制成绩:85
成绩等级为:B
```
阅读全文