+ 1
java
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); here's code i need a explanation for this
3 Respostas
+ 3
Its so easy
+ 3
Ans is 17...if i value is 3 then add 10 to prev result that is from 0 to 2 = 3+10+4 (for i = 4).
+ 1
Jass Ahuja
in loop, all i values are adding to result, except when i=3 so, when i=3, adding 10 to result
result = 0+1+2+ 10 +4 =17
When i=5,i<5 fails so loop stops there.. And print the result.