java编写程序:输入一个学生的成绩,给出相应的等,(用switch语句实现:0-59:D 60-69:C 70-84:B 85-100:A

如题所述

import java.util.Scanner;

/**
*
* @author Administrator
*/
public class TestSwitch {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner scanner = new Scanner(System.in);
int scort = scanner.nextInt();
if (scort >= 0 && scort <= 100) {
switch (scort / 10) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
System.out.println("D");
break;
case 6:
System.out.println("C");
break;
case 7:
System.out.println("B");
break;
case 8:
if (scort < 85) {
System.out.println("B");
} else {
System.out.println("A");
}
break;
case 9:
case 10:
System.out.println("A");
break;
default:
break;
}
} else {
System.out.println("请输入正确的得分[0-100]!!!");
}
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-03-17
为什么做到选择的时候想到的都是switch呢,你这问题完全可以用if else if来判断啊,这样不是更快吗if(0<=score<=59){} else if(60<=score<=69){} else if()。。。。。。
第2个回答  2012-03-17
if else方面点