- 2

what is the answer?

for loop int r =0 for(i=0;i<5;i++){ if (i==3) r +=10 else r +=I } system. out.printin(r)

5th Sep 2016, 2:22 PM
gurkirt Singh
gurkirt Singh - avatar
10 ответов
+ 3
for the values of i = 0, 1, 2 - you get the value of r as 3. 0+1+2. then when i equals 3, r value changes to 3+10=13. then the loop goes for i=4, where the r value changes again as 13+4=17. so, r=17
5th Sep 2016, 4:44 PM
vidhi
+ 3
r=0 r=1 r=1+2 r=1+2+10 r=1+2+10+4=17 i=5 , so, this is the end
5th Sep 2016, 11:29 PM
Александр Евдокимов
Александр Евдокимов - avatar
+ 2
When you enter the for loop the first time : i=0, r=0 2nd: i=1, r=0 while leaving loop r =1,i=2 3rd time entering loop : i=2, r =1 while leaving both are 3 4th time i enters the if block, r becomes 13 5th time it skips if block, here r=13 i=4 so while leaving r becomes 17, i becomes 5 6th time i <5 not true so it skips for block and prints r as 17
5th Sep 2016, 4:49 PM
Yugesh Kekre
Yugesh Kekre - avatar
+ 2
The Answer is 14 When i=0; x=1; When i=1; x=2; When i=2; x=3; When i=3; x=13; When i=4; x=14; When i=5; the loop condition is end
6th Sep 2016, 7:38 AM
Alexander Nicholas S.
Alexander Nicholas S. - avatar
+ 1
If u place the statement "System.out.println(r) ;" inside the for loop you can see the result of each loop at the output of the program. The result of the above program is then: 1 2 3 13 14
10th Sep 2016, 11:43 AM
Ashish Lama
Ashish Lama - avatar
+ 1
if it is i 17.and it is 1 14
14th Sep 2016, 4:00 PM
ESWAR
ESWAR - avatar
+ 1
r=0 r=1 r=1+2 so r=3 if condition exicute r=3+10 r=10+4 else condition exicute
20th Sep 2016, 1:24 AM
Sheik Mohamed Tanseer
Sheik Mohamed Tanseer - avatar
0
answer is 14.
5th Sep 2016, 2:51 PM
Raj Joshi
Raj Joshi - avatar
0
no its 17
5th Sep 2016, 3:28 PM
gurkirt Singh
gurkirt Singh - avatar
0
it is i or 1
14th Sep 2016, 4:00 PM
ESWAR
ESWAR - avatar