+ 4

Arrays

Hi Guys, can anyone explain why the output of the code below is 17? Please? TIA! public class Program { public static void main(String[] args) { int result = 0; for (int i = 0; i < 5; i++) { if (i == 3) { result += 10; } else { result += i; } } System.out.println(result); } }

6th Dec 2016, 5:53 AM
Lyka O. Matilla
Lyka O. Matilla - avatar
4 Antworten
+ 4
0 + 1 + 2 + 10 + 4 = 17
6th Dec 2016, 6:25 AM
Karl T.
Karl T. - avatar
+ 1
wrongly managed value....
6th Dec 2016, 6:12 AM
Dhiraj singh✔️
Dhiraj singh✔️ - avatar
0
You are updating same variable "result" in both if else conditions 1 3 13 17
7th Dec 2016, 9:05 PM
Bhupinder Singh
Bhupinder Singh - avatar
0
Invertir u array de tipo char
31st Aug 2021, 7:14 AM
Karol Marcela Marin Pastuzano
Karol Marcela Marin Pastuzano - avatar