+ 1
Help please
Can someone explain this code to me? How does the output come to be 17? int result = 0 for (int i = 0; i <5; i++) { if (i==3) { result += 10; } else { result += i; } } System.out.println(result);
3 Réponses
+ 5
when I=1
result+=I so result is 1
when I=2
result+=I so result is 1+2 ==3
when I=3
result+=10 because I==3 so 3+10==13
when I =4
result+=4 si 13+4==17
and when I==5
the for loop stops running since I should be less than 5
+ 4
yes the other answerer correctly
+ 1
Oh I get it now. Thank you very much