- 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)
10 Respostas
+ 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
+ 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
+ 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
+ 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
+ 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
+ 1
if it is i 17.and it is 1 14
+ 1
r=0
r=1
r=1+2 so r=3 if condition exicute
r=3+10
r=10+4 else condition exicute
0
answer is 14.
0
no its 17
0
it is i or 1