+ 1

Can any one explain this?

Its a challenge in java i really cant understand! public class Program { public static void main(String[] args) { int a=1;int f=5; for (; (a+=f+1)<7;) { f=a% (f+1); } System.out.print (f*a); } } output: 35 but but.. how??

6th Jul 2017, 4:37 PM
I Am RG
I Am RG - avatar
2 Answers
0
there is no initialization & there is no something todo after finishing loop. there is only condition so FOR was written like that for(; condition. ;) condition: a=a+f+1=1+5+1=7 so a<7 is false.. so skip for loop, it won't be executed finally print f*a=5*7=35
6th Jul 2017, 4:47 PM
Dina
Dina - avatar
+ 1
Thank you! ;) @Dina
6th Jul 2017, 5:40 PM
I Am RG
I Am RG - avatar