下面的方法,当输入为2的时候返回值是多少?
复制代码
1
2
3
4
5
6
7
8
9
10
11
12public 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; }
正确答案: D
解析:注意 题中switch结构中没有break, switch case 方法中若没有break来跳出,则程序就会从第一个匹配上的case一直执行到整个结构结束。最后
以上就是怕黑水杯最近收集整理的关于【超坑人的面试题】switch没有break 正确答案: D 的全部内容,更多相关【超坑人的面试题】switch没有break内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复