- 1
How the output is 18 can anyone understand me briefly please....
public class Program { public static void main(String[] args) { int res=0; for(int i=1; i<=10; i+=3){ if(10/i==2){ continue; } res+=i; } System.out.println(res); // output 18 } }
3 ответов
+ 2
Let's see what happens in every iteration :-
i = 1
10/1 = 10 != 2 (condition false)
res = 1
i = 4
10/4 = 2.5 == 2 (condition true)
res = 1
i = 7
10/7 = 1.42 != 2(condition false)
res = 1 + 7 = 8
i = 10
10/10 = 1 != 2 (condition false)
res = 8 + 10 = 18
Thus answer is 18
0
Oh i understand i thinking wrong
10/4==2.5 or 2 ( condition false)
Now understand clearly.
Thank for answering me🙏