40. switch 语句
语法讲解
今天学: switch 根据变量的值匹配不同的 case 执行。break 用于跳出 switch。
public class Main {
public static void main(String[] args) {
int day = 3;
switch (day) {
case 1:
System.out.println("Mon");
break;
case 2:
System.out.println("Tue");
break;
case 3:
System.out.println("Wed");
break;
default:
System.out.println("Other");
}
}
}
小练习
输出是什么?
提交要求: 只提交最终输出结果,不要添加多余的说明或引号。
全部评论