3、switch结构判断成绩
90-100 A
80-89 B
70-79 C
60-69 D
<60 E
使用switch结构
代码如下:
public class Score {
public static void main(String[] args) {
// TODO Auto-generated method stub
while (true) {
System.out.println("请输入分数:");
Scanner sc = new Scanner(System.in);
double score = sc.nextDouble();
int c = (int) (score / 10);
switch (c) {
case 10:
case 9: {
System.out.println("A");
break;
}
case 8:
System.out.println("B");
break;
case 7:
System.out.println("C");
break;
case 6:
System.out.println("D");
break;
default:
System.out.println("E");
break;
}
}
}
}