Arrays | Sololearn: Learn to code for FREE!

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

12/6/2016 5:53:46 AM

Lyka O. Matilla

4 Answers

New Answer

+4

0 + 1 + 2 + 10 + 4 = 17

+1

wrongly managed value....

0

You are updating same variable "result" in both if else conditions 1 3 13 17

0

Invertir u array de tipo char