+ 1

problem

why the answer of this question is 17? 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);

31st Aug 2017, 9:00 AM
kais hasan
kais hasan - avatar
2 Respuestas
+ 12
This is what happens: i = 0: result = 0 + 0 i = 1: result = 0 + 1 i = 2: result = 1 + 2 i = 3: result = 3 + 10 i = 4: result = 13 + 4 So when the loop is finished, result is 17.
31st Aug 2017, 9:20 AM
Tashi N
Tashi N - avatar
+ 1
thank you❤❤
31st Aug 2017, 9:29 AM
kais hasan
kais hasan - avatar