- 1

is there anyOne who can Solve this for me???????? and why 17 ans????

int result = 0; for (int i = 0; i < 5; i++) { if (i == 3) { result += 10; } else { result += i; } } System.out.println(result);

20th Oct 2017, 4:42 PM
Ishtiaq Hussain
Ishtiaq Hussain - avatar
2 ответов
+ 13
int result = 0; for (int i = 0; i < 5; i++) { if (i == 3) { result += 10; } else { result += i; } } System.out.println(result); Explanation : 1. when I=0 else condition executed result =0 2. when I=1 else condition executed result =0+1 3 when I=2 else condition executed result= 1+2 4. when I=3 if condition executed result= 3+10 5. when I=4 else condition executed result =4+13 //hence result is 17
20th Oct 2017, 4:55 PM
P R
P R - avatar
- 1
i goes like this 0 1 2 3 4 whenever i is 3 its +10 with result else +i so... i=0...result is 0+0 i=1.....result is 0+1 i=2....result is 1+2 i=3....result is 3+10 i=4....result is 13+4--->17
20th Oct 2017, 4:51 PM
sayan chandra
sayan chandra - avatar