day03--选择流程-switch语句-数据类型-case穿透的注意事项
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.inmind.switch02;
|
||||
/*
|
||||
switch语句中,表达式的数据类型,可以是byte,short,int,char,enum(枚举),JDK7后可以接收String。
|
||||
switch语句中,case穿透:break不写,当某一个case满足条件,就开始执行之后的语句,如果没有遇到break,会
|
||||
继续向下执行,直接遇到break,或者switch语句结束
|
||||
*/
|
||||
public class Demo04 {
|
||||
public static void main(String[] args) {
|
||||
//请根据输入的月份,输出是什么季节 3~5春天 6~8夏天...
|
||||
int month = 15;
|
||||
switch (month){
|
||||
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;
|
||||
case 12:
|
||||
case 1:
|
||||
case 2:
|
||||
System.out.println("冬天");
|
||||
break;
|
||||
default:
|
||||
System.out.println("您输入的值有误,只能是1~12");
|
||||
break;
|
||||
}
|
||||
System.out.println("程序结束");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user