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.

Subtopic: Iteration Clear filter

Questions 221–230 of 376
  1. 221
  2. 222
  3. 223
  4. 224
  5. 225
  6. 226
  7. 227
  8. 228
  9. 229
  10. 230

Question 221

Multiple choice Iteration
Consider the following code segment.
int total = 0;
for (int i = 1; i <= 6; i++)
{
    if (i % 2 == 0 || i < 3)
        total = total + i;
}
What value is stored in total after the loop finishes?
Pick an answer, then check it. The solution opens in a window.

Question 222

Multiple choice Iteration
Consider the following code segment. int x = 40; int count = 0; while (x > 3) { if (x % 2 ==…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 223

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

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 224

Multiple choice Iteration
Consider the following method. public static int mystery(int n) { int count = 0; while (n > 0) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 225

Multiple choice Iteration
Consider the following code segment.
int count = 0;
for (int i = 1; i <= 4; i++)
{
    for (int j = i; j <= 4; j++)
        count++;
}
What is the value of count after the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 226

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

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 227

Multiple choice Iteration
Consider the following code segment.
int n = 81;
int count = 0;
while (n > 1)
{
    if (n % 3 == 0)
        n = n / 3;
    else
        n = n - 1;
    count++;
}
What value is stored in count after the loop terminates?
Pick an answer, then check it. The solution opens in a window.

Question 228

Multiple choice Iteration
Consider the following code segment. int value = 3; for (int k = 0; k…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 229

Multiple choice Iteration
Consider the following method.
public static int process(int n)
{
    int result = 0;
    while (n > 0)
    {
        result = result + n % 10;
        n = n / 100;
    }
    return result;
}
What value is returned by process(58364) ?
Pick an answer, then check it. The solution opens in a window.

Question 230

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

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 221 of 376
Page 23 of 38