Switch语句(春夏秋冬)
//case穿透
//case穿透
//case穿透
case后面没有break将会穿透,直到遇到break或者整体switch结束。
package class1;
// 12个月 输入一个月,判断春夏秋冬
import java.util.Scanner;
public class thirty_eight {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个月份");
int month = sc.nextInt();
switch(month){
case 1:
System.out.println("1月是冬天");
break;
case 2:
System.out.println("2月是冬天");
break;
case 3:
System.out.println("3月是春天");
break;
case 4:
System.out.println("4月是春天");
break;
case 5:
System.out.println("5月是春天");
break;
case 6:
System.out.println("6月是夏天");
break;
case 7:
System.out.println("7月是夏天");
break;
case 8:
System.out.println("8月是夏天");
break;
case 9:
System.out.println("9月是秋天");
break;
case 10:
System.out.println("10月是秋天");
break;
case 11:
System.out.println("11月是秋天");
break;
case 12:
System.out.println("12月是冬天");
break;
default:
System.out.println("输入的数字不合理");
break;
}
}
}
//case穿透//case穿透//case穿透//case穿透//case穿透//case穿透//case穿透//case穿透//case穿透//case穿透//case穿透
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;
default:
System.out.println("输入的数字不合理");
break;