diff --git a/day03/src/com/inmind/switch02/Demo04.java b/day03/src/com/inmind/switch02/Demo04.java new file mode 100644 index 0000000..3bfa94e --- /dev/null +++ b/day03/src/com/inmind/switch02/Demo04.java @@ -0,0 +1,35 @@ +package com.inmind.switch02; +/* +switch语句中,表达式的数据类型,可以是byte,short,int,char,enum(枚举),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; + + } + } +}