+ 1

Why output is 17?

int result = 0; for (int i = 0; i < 5; i++) { if (i == 3) { result += 10; } else { result += i; } } System.out.println(result);

2nd Oct 2018, 11:17 PM
Luko Kennedy Lukilo
Luko Kennedy Lukilo - avatar
4 Respostas
+ 6
If you hand trace the execution of the code, you will get a sum of 0, 1, 2, 10, 4 to result. The result is then printed, which is the value 17. Btw, you can actually use the search bar. I remember answering to this since an eternity ago. https://www.sololearn.com/Discuss/497243/?ref=app
2nd Oct 2018, 11:29 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Hatsy Rei thank you
16th Oct 2018, 7:12 AM
Garima Chauhan
0
Supriya Gangapatnam thank you 👍🏻
16th Oct 2018, 7:12 AM
Garima Chauhan