选择结构
if多选择结构
public static void main(String[] args) {
Scanner scanner= new Scanner(System.in);
System.out.println("请输入成绩");
int score = scanner.nextInt();
if(score==100){
System.out.println("恭喜满分");
}
else if(score>=80&&score<100){
System.out.println("A级");
} else if(score>=60&&score<80){
System.out.println("B级");
} else if(score>=0&&score<60){
System.out.println("不合格");
} else {
System.out.println("成绩不合法");
}
}
switch选择结构
switch case
package base;
import java.util.Scanner;
public class Switch {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String grade = scanner.next();
switch(grade){
case"A":
System.out.println("优秀");
break;
case"B":
System.out.println("良好");
break;
case"C":
System.out.println("及格");
break;
case"D":
System.out.println("再接再厉");
break;
default:
System.out.println("成绩有误");
}
}
}
jdk7后switch支持字符串