+ 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);
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.
0
thanks