以下代码中,输入2时result的值为: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; }
- A、6
- B、2
- C、4
- D、10
答案:D
package test;
public class TestTest {
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;
}
}