switch

 1 package com.cn;
 2 
 3 public class Test {
 4     public static void main(String agrs[]){
 5         int x = 1;
 6         switch(x){
 7             case 1 : 
 8                 System.out.println("1");
 9             case 2 :
10                 System.out.println("2");
11             default :
12                 System.out.println("others");
13         }
14     }
15 }

输出结果:

1
2
others

package com.cn;

public class Test {
    public static void main(String agrs[]){
        int x = 2;
        switch(x){
            case 1 : 
                System.out.println("1");
            case 2 :
                System.out.println("2");
            default :
                System.out.println("others");
        }
    }
}

输出结果:

2
others

 1 package com.cn;
 2 
 3 public class Test {
 4     public static void main(String agrs[]){
 5         int x = 2;
 6         switch(x){
 7             case 1 : 
 8                 System.out.println("1");
 9                 break;
10             case 2 :
11                 System.out.println("2");
12                 break;
13             default :
14                 System.out.println("others");
15         }
16     }
17 }

输出结果:

2

 1 package com.cn;
 2 
 3 public class Test {
 4     public static void main(String agrs[]){
 5         int x = 2;
 6         switch(x){
 7             case 1 : 
 8                 System.out.println("1");
 9                 break;
10             case 2 :
11             case 3 :
12                 System.out.println("2");
13                 break;
14             default :
15                 System.out.println("others");
16         }
17     }
18 }

输出结果:

2

posted @ 2016-01-03 22:03  伊小白  阅读(195)  评论(0编辑  收藏  举报