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 2,571–2,580 of 2,811
  1. 2571
  2. 2572
  3. 2573
  4. 2574
  5. 2575
  6. 2576
  7. 2577
  8. 2578
  9. 2579
  10. 2580

Question 2571

Multiple choice Unit 4: Data Collections
What is printed? int[][] m = {{2,7,6}, {9,5,1}, {4,3,8}}; int sum = 0; for (int i = 0;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2572

Multiple choice Unit 4: Data Collections
What does arr contain after the following code? int[] arr = {5, 2, 8, 1, 9, 3}; for (int i = 0; i <…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2573

Multiple choice Unit 4: Data Collections
What is printed? ArrayList<String> words = new ArrayList<String>(); words.add("cat"); words.add("car"); words.add("dog"); words.add("care"); words.add("card");…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2574

Multiple choice Unit 4: Data Collections
The following method performs binary search and returns the number of comparisons made. What does bSearch(arr, 23) return? public static int bSearch(int[] arr,…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2575

Multiple choice Unit 4: Data Collections
Selection sort finds the minimum element and swaps it to the front. After exactly 2 complete passes of selection sort on the following array, what is the array?…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2576

Multiple choice Unit 4: Data Collections
What is mystery(7)? public static int mystery(int n)…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2577

Multiple choice Unit 4: Data Collections
This code finds the maximum value in each column and sums them. What is printed? int[][] grid = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}}; int result = 0; for (int c…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2578

Multiple choice Unit 4: Data Collections

What is printed?

ArrayList<Integer> list = new ArrayList<Integer>();
list.add(4); list.add(4); list.add(3);
list.add(4); list.add(4);
for (int i = 0; i < list.size(); i++) {
    if (list.get(i) == 4) {
        list.remove(i);
    }
}
System.out.println(list);
Pick an answer, then check it. The solution opens in a window.

Question 2579

Multiple choice Unit 4: Data Collections

What is printed?

int[][] grid = {{3, 1, 4, 1},
               {5, 9, 2, 6},
               {5, 3, 5, 8}};
int maxCol = 0;
int maxSum = 0;
for (int c = 0; c < grid[0].length; c++) {
    int colSum = 0;
    for (int r = 0; r < grid.length; r++) {
        colSum += grid[r][c];
    }
    if (colSum > maxSum) {
        maxSum = colSum;
        maxCol = c;
    }
}
System.out.println(maxCol + " " + maxSum);
Pick an answer, then check it. The solution opens in a window.

Question 2580

Multiple choice Unit 4: Data Collections

What is printed?

int[][] m = {{1, 2, 3, 4},
             {5, 6, 7, 8},
             {9, 10, 11, 12}};
int sum = 0;
for (int r = 0; r < m.length; r++) {
    for (int c = 0; c < m[0].length; c++) {
        if ((r + c) % 2 == 0) sum += m[r][c];
    }
}
System.out.println(sum);
Pick an answer, then check it. The solution opens in a window.
Question 2,571 of 2,811
Page 258 of 282