How output is 35 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How output is 35

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) } }

25th Aug 2017, 10:54 AM
Md Tauseef Kamal
Md Tauseef Kamal - avatar
2 Answers
+ 3
The value of a becomes 7 as a+=f+1 i.e. a = a + f + 1 = 1 + 5 + 1 = 7 But the value of f doesn't change because loop doesn't execute as the condition becomes false in for loop. So, the product f*a gets printed i.e. 35.
25th Aug 2017, 11:06 AM
Amit Dubey
Amit Dubey - avatar
0
thanks #amit
25th Aug 2017, 11:08 AM
Md Tauseef Kamal
Md Tauseef Kamal - avatar