用if语句我写出来了
int a = 0;
if (a<0 || a>100) {
System.out.println("成绩输入错误,请重试");
}else if (a>=90) {
System.outprintln("A等");
}else if (a>=80) {
System.outprintln("B等");
}else if (a>=70) {
System.outprintln("C等");
}else if (a>=60) {
System.outprintln("D等");
}else {
System.outprintln("E等");
}
问一下用switch语句怎么写???
头大了,,,,,求指教!!!! 作者: Five_伍 时间: 2015-8-23 21:35
陆军老大哥,居然作弊,。
if(x>100||x<0){ //保证输入的值合法性
System.out.println("输入的数据不合法...");
}else
switch (x/10) {
case 10:
case 9:
System.out.println("优");
break;
case 8:
System.out.println("良");
break;
case 7:
System.out.println("差");
break;
case 6:
System.out.println("合格");
break;
case 5:
case 4:
case 3:
case 2:
case 0:
case 1:
System.out.println("不及格");
break;
}