Given:
What is the result?
Given:
What is the result?
The code initializes x to 0 and y to 6, and it evaluates the condition in the for loop where it increments x and decrements y each iteration. The loop continues as long as x is less than y. Inside the loop, there is a condition that checks if x is even using x%2==0, and if it is, it uses continue to skip the rest of the loop iteration. Therefore, the loop will skip printing any values when x is even. When x is 1 and y is 5, the condition x%2==0 is false, so it prints 1-5. The next possible time it would print is when x is 3 and y is 3, but x is no longer less than y, so the loop ends. Hence, the only output is 1-5.
I followed examtopics and I FAILED
1-5 is the correct, print only when x is a impar number => result can be 1-5 and 3-3 but 3-3 so no match with the for condition (x<y) so breack loop and print only 1-5
public class Tester { public static void main(String[] args) { int x = 0, y = 6; for (; x < y; x++, y--) { if (x % 2 == 0) { continue; } System.out.println(x + "-" + y); } } } Result: 1-5 , choose C.
x = 0 y = 6 1st iteration 0 < 6 true 0%2 = 0 == 0? true continue to 2nd iteration 2nd iteration 1 < 5 true 1%2 = 1 == 0 ? false print 1 - 5 x = 2 y = 4 3rd iteration 2 < 4 true 2%2 = 0 ==0? true continue to 4th iteration 4th iteration 3 < 3 false end.
c is correct
b is correct: ublic class Principal { public static void main(String[] args) { int x = 0, y = 6; for (; x < y; x++, y--) { System.out.println(x + "-" + y); } } } 0-6 1-5 2-4
C-Correct
Bad answered, delete the if code block
C-Correct
C is correct
C - Correct Answer
C is correct