day03-选择流程-switch语句-数据类型-case穿透的注意事项
This commit is contained in:
35
day03/src/com/inmind/switch02/Demo04.java
Normal file
35
day03/src/com/inmind/switch02/Demo04.java
Normal file
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user