首页 > 试题广场 >

下面的方法,当输入为2的时候返回值是多少?public st

[单选题]
下面的方法,当输入为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;
}


  • 0
  • 2
  • 4
  • 10
如果case没有break的话,会继续执行后面的语句
发表于 2019-08-20 22:05:54 回复(0)
没有break,发生case穿透现象,程序会继续向下执行,直到遇到break或者结束switch语句的大括号为止。
发表于 2019-09-23 19:04:27 回复(0)
2*2+2*3得10
发表于 2019-08-21 12:32:18 回复(1)
缺少break。语句从第二句一直往下执行
发表于 2019-09-20 19:11:39 回复(0)

因为在case2中没有break,所以程序执行完case2时会继续执行接下来的代码

发表于 2019-09-07 23:48:24 回复(0)