Verityprep
Question Bank

AP® Computer Science A Multiple Choice Questions

Work through AP Computer Science A multiple-choice questions unit by unit, 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 1,071–1,080 of 2,811
  1. 1071
  2. 1072
  3. 1073
  4. 1074
  5. 1075
  6. 1076
  7. 1077
  8. 1078
  9. 1079
  10. 1080

Question 1071

Multiple choice Unit 2: Selection and Iteration
A binary search is performed on the sorted array a = {3, 8, 14, 20, 27, 35, 44, 56, 71, 89} looking for the value 56. The search uses the standard recurrence…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1072

Multiple choice Unit 2: Selection and 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 1073

Multiple choice Unit 2: Selection and 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 1074

Multiple choice Unit 2: Selection and 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 1075

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

Question 1076

Multiple choice Unit 2: Selection and 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 1077

Multiple choice Unit 2: Selection and 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 1078

Multiple choice Unit 2: Selection and 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 1079

Multiple choice Unit 2: Selection and Iteration
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 1080

Multiple choice Unit 2: Selection and Iteration
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 1,071 of 2,811
Page 108 of 282