Question 1101
Consider the following code segment.
int x = 4;
int y = 6;
if (x + y > 10)
{
x = y - x;
}
else
{
y = x + y;
}
if (x * 2 >= y)
{
y = y - x;
}
else
{
x = x + y;
}
System.out.println(x + " " + y);
What is printed?
Main Solution
Answer
Answer: D. The first condition is false because 4 + 6 is not greater than 10, so y becomes 10. Then x * 2 is 8, which is less than 10, so x becomes 14.
Answer: Correct: D
A
10 6
B
4 10
C
2 4
D
14 10
Answer images

