public class test2 {
public static void main(String[] args) {
Scanner scanTest = new Scanner(System.in);
System.out.println("请输入一个数:");
int t = scanTest.nextInt();
switch (t) {
case 1: {
System.out.println("this is 1");
break;
}
case 2: {
System.out.println("this is 2");
break;
}
case 3: {
System.out.println("this is 3");
break;
}
default: {
System.out.println("this is default");
break;
}
}
public static void main(String[] args) {
Scanner scanTest = new Scanner(System.in);
System.out.println("请输入一个数:");
int t = scanTest.nextInt();
switch (t) {
case 1: {
System.out.println("this is 1");
break;
}
case 2: {
System.out.println("this is 2");
break;
}
case 3: {
System.out.println("this is 3");
break;
}
default: {
System.out.println("this is default");
break;
}
}
}
switch语句,定义一个变量t,然后在控制台输入一个数字,当输入的数字符合case 1就执行,以此类推。