下面的方法,当参数值为2的时候返回值是多少public 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: 10
B: 8
C: 6
D: 4
E: 2
F: 0
A: 10
B: 8
C: 6
D: 4
E: 2
F: 0
举一反三
- 下面的方法,当输入为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; }
- 以下代码执行的结果是:( )int i=2;int result = 0;switch (i) {case 1:result = result + i;case 2:result = result + i * 2;case 3:result = result + i * 3;}System.out.println(result); A: 0 B: 2 C: 4 D: 10
- 下面程序段的输出结果是( )。 public class Test public static void main ( String[] args) int result=0; for ( int i=1;i<=5;i++) if ( i%2==0 ) continue; result + =i; System. out. println ("result is " + result ); A: result is 7 B: result is 8 C: result is 9 D: result is 10
- 以下代码运行后,result的值为() var result = 0; for (var i = 2; i <=10; i+=2) { result *= i*i }
- 下列语句的执行结果是: result = 0 i = 1 while result <; 10: result += i i += 1 if i >; 2: break print(result) A: 3 B: 5 C: 7 D: 10