+ 4
How is the result 17 please i need good explanation on this, anybody please? 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);
8 odpowiedzi
+ 7
i=0 <5(true) result=0+0=0
i=1 <5(true) result=0+1=1
i=2 <5(true) result=1+2=3
i=3 <5(true) result=3+10=13 (if i=3)
i=4 <5(true) result=13+4=17
i=5 <5(false) Stop loop
+ 7
1. 0+0=0 // when i = 0 add 0
2. 0+1=1 // when i =1 add 1
3. 1+2=3 // when i = 2 add 2
4. 3+10=13 // when i = 3 add 10
5. 13+4=17 // when i = 4 add 4
6 . 5 is not less than 5
Hence answer is 17
+ 5
@didi in second last line update 13+4=17
+ 3
Thank you all
I really appreciate
+ 2
thx @Sizr
0
thx guyz.
0
befor i==3 it executing else condition and when i became 3 , it will add 10 after that again continue with else .