Verityprep
Question Bank · Unit 2

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.

Questions 411–420 of 692
  1. 411
  2. 412
  3. 413
  4. 414
  5. 415
  6. 416
  7. 417
  8. 418
  9. 419
  10. 420

Question 411

Multiple choice Iteration
Consider the following code segment. int total = 0; for (int i = 1; i <= 7; i++) { total…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 412

Multiple choice Boolean Expressions
Which of the following is true exactly when n is outside the range 5 through 12, inclusive?
Pick an answer, then check it. The solution opens in a window.

Question 413

Multiple choice Iteration
Consider the following code segment. int sum = 0; for (int k = 2; k <= 9; k = k + 2) { if (k…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 414

Multiple choice Boolean Expressions
Suppose a, b, and c are int variables. Which of the…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 415

Multiple choice Iteration
Consider the following code segment. int n = 18; int total = 0; while (n > 0) { total…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 416

Multiple choice Iteration
Consider the following code segment. int result = 1; for (int i = 0; i <…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 417

Multiple choice Boolean Expressions
Consider the following method.
public static int process(int n)
{
    int count = 0;

    while (n >= 10)
    {
        if (n % 2 == 0)
            n = n / 2;
        else
            n = n - 1;
        count++;
    }

    return count;
}
What value is returned by process(19) ?
Pick an answer, then check it. The solution opens in a window.

Question 418

Multiple choice Boolean Expressions
Consider the following code segment. int x = 3; int y = 8; if (x > 4 && y++ > 7) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 419

Multiple choice Iteration
Consider the following code segment. int total = 0; for (int i = 1; i <= 5; i++) { if (i % 2 ==…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 420

Multiple choice Iteration

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?

Pick an answer, then check it. The solution opens in a window.
Question 411 of 692
Page 42 of 70