Verityprep
Question Bank · Unit 4

AP® Computer Science A Data Collections Practice Questions

Work through AP Computer Science A practice 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 931–940 of 1,222
  1. 931
  2. 932
  3. 933
  4. 934
  5. 935
  6. 936
  7. 937
  8. 938
  9. 939
  10. 940

Question 931

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 932

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 933

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 934

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 935

Free response Arraylists
The Arctic Research Station Polaris-7 collects hourly temperature readings from its sensor array. Scientists store these readings in an ArrayList<Double> and…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 936

Free response 2D Arrays
The Meridian Concert Hall uses a digital seating management system. The venue is represented as a 2D array of boolean values where true indicates an occupied…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 937

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 938

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 939

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 940

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 931 of 1,222
Page 94 of 123