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 391–400 of 692
  1. 391
  2. 392
  3. 393
  4. 394
  5. 395
  6. 396
  7. 397
  8. 398
  9. 399
  10. 400

Question 391

Multiple choice Iteration
Consider the following code segment.
int[][] g = { {3, 8, 2},
               {5, 1, 9},
               {4, 6, 7} };
int count = 0;
for (int r = 0; r < g.length; r++)
{
    int rowMax = g[r][0];
    for (int c = 1; c < g[r].length; c++)
    {
        if (g[r][c] > rowMax)
        {
            rowMax = g[r][c];
        }
    }
    for (int c = 0; c < g[r].length; c++)
    {
        if (g[r][c] == rowMax)
        {
            count = count + 1;
        }
    }
}
System.out.println(count);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 392

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 393

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 394

Multiple choice Boolean Expressions
Which of the following is equivalent to !(x > 5 && y != 2) ?
Pick an answer, then check it. The solution opens in a window.

Question 395

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 396

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 397

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 398

Multiple choice Boolean Expressions
Consider the following declarations.
int x = 4;
int y = 9;
boolean b = x > 5 || y / x == 2;
What is the value of b after the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 399

Multiple choice Boolean Expressions
Which of the following conditions is true exactly…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 400

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 391 of 692
Page 40 of 70