码迷,mamicode.com
首页 > 其他好文 > 详细

switch

时间:2016-09-13 13:16:29      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

 switch后面如果有一条case不加break的话,那么会将后面的case全部执行,不管是不是满足case的条件

如:

public class Example {

    public static void main(String args[]) {
        System.out.println(getValue(2));;
    }

    public static int getValue(int i) {
        int result = 0;
        switch (i) {
        case 1:
            result = result + i;
        case 2:
            result = result + i * 2;
        case 3:
            result = result + i * 3;
        }
        return result;
    }
}

 

switch

标签:

原文地址:http://www.cnblogs.com/yzjT-mac/p/5867826.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!