0

Why is the output 17 ? (this is the array modul quiz(SoloLearn)) int result = 0; for (int i = 0; i < 5; i++){ if (i == 3) { result += 10; }else{ result += i; } } System.out.println (result);

22nd Jul 2016, 9:41 AM
Peter Müller
Peter Müller - avatar
5 odpowiedzi
+ 1
check the for loop, variable "result" is added everytime with the I value and added by 10 when value of I is 3. so each time loop runs the value of result changes. 0+1+2+10+4=17.
22nd Jul 2016, 9:12 PM
Amit Karn
Amit Karn - avatar
0
never mind, got it;)
22nd Jul 2016, 9:58 AM
Peter Müller
Peter Müller - avatar
0
can you explain?
22nd Jul 2016, 5:14 PM
.com
.com - avatar
0
resultv= result + i i=0 result=0 i=1 result=1 i=2 result=3 i=3 result=13 i=4 result=17
23rd Jul 2016, 3:18 PM
Hardik Patel
Hardik Patel - avatar
0
it be 17
26th Dec 2020, 10:06 AM
Abdulraouf Ahadi
Abdulraouf Ahadi - avatar