0

What is the output of this code? int result = 0; for (int i = 0; i < 5; i++) { if (i == 3) { result += 10; } else {

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);

27th Jun 2017, 2:43 PM
Walter Mugo
Walter Mugo - avatar
5 Antworten
+ 3
17 checked with my netbeans lol when i = 0, result = 0 when i = 1, result = 1 when i = 2, result = 3 when i = 3, result = 13 when i = 4, result = 17 i can only reach 4 because i < 5
27th Jun 2017, 2:54 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 1
17
8th Apr 2021, 9:31 AM
sangeetha pyla
sangeetha pyla - avatar
0
yeah that's what i arrived at too (result=17)
27th Jun 2017, 3:11 PM
Amu
0
17
28th Oct 2021, 7:19 PM
Chaitanya Waghmode
Chaitanya Waghmode - avatar