+ 1

Explain solution

https://sololearn.com/compiler-playground/cZlm3IzN1oFj/?ref=app Question: int f=1, int i=2; While (++i>2){ f*=i; if(f>=20){ i/=2; f+=1; } } System.out.println(f); At first while(2+1>2) that's true and it countines Second f= 1* 2=2. 2+ :printLN If (f >=20) i=20 / 2= 10. Third f+=1 : [ f= 1+ (1 to 10)] 2+4+5+6+7+8+9+10+11:printLN f = 2 + ( i=3 + i=4 + i=5 + i=6 + i=7 + i=8 + i=9 + i=10 + (i=10 + 1). https://sololearn.com/compiler-playground/cZlm3IzN1oFj/?ref=app

5th Jan 2024, 1:34 PM
MIlad Khan
MIlad Khan - avatar
13 Respostas
+ 1
the code do: 1*3 3*4 12*5 int( 5/2) 60+2 EDIT: after code has changed from f+=i to f+=1 result is 60+1
6th Jan 2024, 10:47 PM
zemiak
0
And what happened for last function f+=1? ! (62 +1)
6th Jan 2024, 10:59 PM
MIlad Khan
MIlad Khan - avatar
0
last operation is f+=i where f=60 and i =2
6th Jan 2024, 11:07 PM
zemiak
0
It was typed f+=1 and this 60+1 not 2
6th Jan 2024, 11:09 PM
MIlad Khan
MIlad Khan - avatar
0
That's 1 not i=2
6th Jan 2024, 11:10 PM
MIlad Khan
MIlad Khan - avatar
0
I see, you mean code after "Question:" not in the playground
6th Jan 2024, 11:19 PM
zemiak
0
The most important point in this code it typed: f*=i : 1*2 and again it returns to i/=2 while it's after if (f>=20).
6th Jan 2024, 11:25 PM
MIlad Khan
MIlad Khan - avatar
0
Your answer best answer but at last it gets 61 which that's true ,but 62 is not.
6th Jan 2024, 11:46 PM
MIlad Khan
MIlad Khan - avatar
0
(60+1) and The end
6th Jan 2024, 11:47 PM
MIlad Khan
MIlad Khan - avatar
0
but why there is break ?
7th Jan 2024, 12:11 AM
zemiak