首页 > 其他 > 详细

switch

时间:2016-09-13 13:13:35      阅读:301      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!