+ 1

java array

can you please solve that example? What is the output of this code? int result = 0; for (int i = 0; i < 5; i++) { if (i == 3) { result += 10; } else { result += i; } } System.out.println(result);

27th Nov 2016, 7:08 PM
Gaye
2 ответов
+ 3
At i = 0,1,2,4 result = 0+1+2+4. as result += i i.e., result = result + i. Only when i = 3 then result += 10. So total value of result is 0 + 1 + 2 + 10 + 4 = 17. I have shown for eacc of 5 iterations.
27th Nov 2016, 7:23 PM
Deepak Kumar
Deepak Kumar - avatar
0
thanks
28th Nov 2016, 3:42 PM
Gaye