if else switch判断结构
- if结构
import java.util.Scanner;
public class Demo02 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int x = scanner.nextInt();
if (x>=90 && x<=100){
System.out.println("优秀");
}else if (x>=80 && x<90){
System.out.println("良");
}else if (x>=70 && x<80){
System.out.println("中");
}else if (x>=60 && x<70){
System.out.println("及格");
}else if (x<60 && x>=0){
System.out.println("不及格");
}else {
System.out.println("输入的成绩不合法");
}
}
}
public class Demo03 {
public static void main(String[] args) {
if(false) //if else 语句末尾没有大破号的情况下 默认第一句就是执行体
System.out.println("666");
else
System.out.println("777");
}
}
-
switch结构
import java.util.Scanner; public class Demo007 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String message = scanner.next();//可以使用String类型 switch (message){ case "我是臭保底人": System.out.println("我是阿斯托洛吉斯·莫娜·梅姬斯图斯");break; case "我是欧皇": System.out.println("以理服人大棒");break; case "单抽出奇迹": System.out.println("劳逸结合是不错,但也不要放松过头(爬)");break; case "退坑了退坑了": System.out.println("十连全金");break; default: System.out.println("胡桃池出刻晴");break; } } }