day03-选择流程-switch语句-数据类型-case穿透的注意事项

This commit is contained in:
2026-07-16 15:03:22 +08:00
parent 329131129c
commit 4301a125de

View File

@@ -0,0 +1,35 @@
package com.inmind.switch02;
/*
switch语句中表达式的数据类型可以是byteshortintcharenum枚举String。
switch语句中case穿透break不写当某一个case满足条件就开始执行之后的语句如果没有遇到break
继续向下执行直接遇到break或者switch语句结束
*/
public class Demo04 {
public static void main(String[] args) {
//请根据输入的月份,输出是什么季节(12,1,2 冬季)
int month = 3;
switch (month) {
case 12:
case 1:
case 2:
System.out.println("冬季");
break;
case 3:
case 4:
case 5:
System.out.println("春季");
break;
case 6:
case 7:
case 8:
System.out.println("夏季");
break;
case 9:
case 10:
case 11:
System.out.println("秋季");
break;
}
}
}