1.判断成绩级别
1>.if ····else···
package HelloWorld;
public class studentAchievements {
public static void main(String[] args) {
int score=65;
if(score>100||score<0) System.out.println("成绩错误");
else if(score>90)System.out.println("A");
else if(score>80)System.out.println("B");
else if(score>70)System.out.println("C");
else if(score>60)System.out.println("D");
else System.out.println("不及格");
}
}
2>switch····case····default
package HelloWorld;
public class studentAchievementsSwitch {
public static void main(String[] args) {
int score=90;
switch(score/10) {
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("不及格");
}
}
}
3.if else与switch case的选择
if:判断条件是boolean类型
switch:判断整式表达式。
对于整式,if与switch类似