Verityprep
Question Bank · Unit 4

AP® Computer Science A Data Collections Multiple Choice Questions

Work through AP Computer Science A multiple-choice questions on Data Collections, 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 841–850 of 1,079
  1. 841
  2. 842
  3. 843
  4. 844
  5. 845
  6. 846
  7. 847
  8. 848
  9. 849
  10. 850

Question 841

Multiple choice Arraylists
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 842

Multiple choice Sorting And Searching
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 843

Multiple choice Sorting And Searching
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 844

Multiple choice Recursion
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 845

Multiple choice 2D Arrays
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 846

Multiple choice Arraylists

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 847

Multiple choice 2D Arrays

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 848

Multiple choice 2D Arrays

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 849

Multiple choice Sorting And Searching

After exactly 2 passes of this partial insertion sort, what is the array?

int[] arr = {8, 3, 5, 1, 4};
for (int i = 1; i < 3; i++) {
    int key = arr[i];
    int j = i - 1;
    while (j >= 0 && arr[j] > key) {
        arr[j + 1] = arr[j];
        j--;
    }
    arr[j + 1] = key;
}
Pick an answer, then check it. The solution opens in a window.

Question 850

Multiple choice 2D Arrays

What is printed?

int[][] grid = new int[4][4];
for (int r = 0; r < 4; r++) {
    for (int c = 0; c < 4; c++) {
        if (r <= c) grid[r][c] = 1;
    }
}
int sum = 0;
for (int r = 0; r < 4; r++)
    for (int c = 0; c < 4; c++)
        sum += grid[r][c];
System.out.println(sum);
Pick an answer, then check it. The solution opens in a window.
Question 841 of 1,079
Page 85 of 108