+ 1
Why answer is 124?
int x = 4; for (int i = 1; i < 5; ++i) { if (x % i == 1) { continue; } System.out.print(i); }
2 Respostas
+ 2
The For-loop iterates through 1-4, that means:
4%1 = 0
4%2 = 0
4%3 = 1 so it matches with 1 and continues to the next iteration
4%4 = 0
0
Терещенко Дмитрий
Continue statement is used to jump from the position or block it will used and the Immidate next instructions is applied.
Here value of x is 4 and in for loop if condition is on getting false, it print the value of i and x%i is not equal to 1 in for loop condition i value 1,2,4 so that is printed.
i =1 , x%i = 4%1 = 0 false so it print
i=2 , x%i = 4%2 = 0 false so it print
i=3 , x%i = 4%3 =1 true and it will execute continue statement which is inside if block so next instructions are executed due to jumping from continue statement.
i=4 , x%i = 4%4 =0 false so it print
So this way final printed value is 124.