AP® Computer Science A Selection and Iteration Multiple Choice Questions
Work through AP Computer Science A multiple-choice questions on Selection and Iteration, then check each answer against a worked solution.
Free · no sign-up Open questions need no account. Sign up or log in to open the rest.
Subtopic: Iteration Clear filter
Question 232
Question 233
Question 234
Question 235
Question 236
Question 237
Question 238
Question 239
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
AP® and Advanced Placement® are registered trademarks of the College Board, which is not affiliated with, and does not endorse, Verityprep. Names are used for identification purposes only.

