From c3dcdb0ce854e3415bdba593dd3d1155757e4633 Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Fri, 16 Jan 2026 10:03:53 +0800 Subject: [PATCH] =?UTF-8?q?day03-=E6=B5=81=E7=A8=8B=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E8=AF=AD=E5=8F=A5-=E9=80=89=E6=8B=A9=E6=B5=81=E7=A8=8B-switch?= =?UTF-8?q?=E7=9A=84=E6=B3=A8=E6=84=8F=E4=BA=8B=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day03/src/com/inmind/switch02/Demo06.java | 45 +++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 day03/src/com/inmind/switch02/Demo06.java diff --git a/day03/src/com/inmind/switch02/Demo06.java b/day03/src/com/inmind/switch02/Demo06.java new file mode 100644 index 0000000..d07390b --- /dev/null +++ b/day03/src/com/inmind/switch02/Demo06.java @@ -0,0 +1,45 @@ +package com.inmind.switch02; +/* +case的穿透性 +在switch语句中,如果case的后面不写break,将出现穿透现象,也就是不会在判断下一个case的值, +直接向后运行,直到遇到break,或者整体switch结束。 + + +注意:1.switch中进行选择判断的数据类型是有范围的,只能是byte,short,int,char,枚举,String + 2.case穿透:break可以不写,当某一个case满足条件,就开始执行与语句体,如果没有遇到break + 会继续向下运行,直到遇到break结束或直到switch语句结束 + */ +public class Demo06 { + public static void main(String[] args) { + // 请使用switch 来实现指定的月份是哪个季节???? + int month = 12; + + switch (month) { + case 3: + case 4: + case 5: + System.out.println("春季"); + break; + case 6: + System.out.println("case6"); + case 7: + System.out.println("case7"); + case 8: + System.out.println("case8"); + System.out.println("夏季"); + break; + case 9: + case 10: + case 11: + System.out.println("秋季"); + break; + case 12: + case 1: + case 2: + System.out.println("冬季"); + break; + } + + System.out.println("程序结束"); + } +}