- import java.util.*;
- class swtichDemo {
- public static void main(String[] args) {
- System.out.println("Hello World!");
- Scanner sc=new Scanner (System.in);
- while(true){
- int num=sc.nextInt(); // case 间不可以定义同名变量
- switch(num){
-
- case 3:
- case 4:
- case 5:
- System.out.println(num+"月是春季");
- break;
- case 6:
- case 7:
- case 8:
- System.out.println(num+"月是夏季");
- break;
- case 9:
- case 10:
- case 11:
- System.out.println(num+"月是秋季");
- break;
- case 12:
- case 1:
- case 2:
- System.out.println(num+"月是冬季");
- break;
- default :
- System.out.println("null");
- break;
-
- }
- }
- }
- }
复制代码 |
|