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 1,031–1,040 of 1,079
  1. 1031
  2. 1032
  3. 1033
  4. 1034
  5. 1035
  6. 1036
  7. 1037
  8. 1038
  9. 1039
  10. 1040

Question 1031

Multiple choice 2D Arrays
Consider the following code segment. int[][] m = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; int sum = 0; for (int r = 0; r < m.length; r++) { for (int c = 0; c <…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1032

Multiple choice Arraylists
A method is intended to insert target into an ArrayList<Integer> called nums immediately after the first element that is strictly greater than target. If no…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1033

Multiple choice 2D Arrays
Consider the following method.
public static int f(int n)
{
    if (n <= 1)
    {
        return n;
    }
    return n + f(n - 2);
}
What is returned by the call f(7)?
Pick an answer, then check it. The solution opens in a window.

Question 1034

Multiple choice 2D Arrays
Consider the following code segment. int[][] grid = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; int total = 0; for (int r = 0; r < grid.length; r++) { for (int c = 0;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1035

Multiple choice 2D Arrays
Consider the following code segment. int[][] grid = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int sum = 0; for (int r = 0; r < grid.length; r++) { for (int…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1036

Multiple choice Recursion
Consider the following method. public static int mystery(int n) { if (n <= 0) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1037

Multiple choice Sorting And Searching
Consider using selection sort (which repeatedly finds the minimum of the unsorted portion and swaps it with the…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1038

Multiple choice Sorting And Searching
Consider using insertion sort (processing index i from 1 upward, inserting arr[i] into the sorted prefix arr[0..i-1]) on the array {8, 2, 6, 1, 4}. What is the array after the first three iterations (i = 1, 2, 3) of the outer loop?
Pick an answer, then check it. The solution opens in a window.

Question 1039

Multiple choice Arrays
Consider the sorted array {2, 4, 7, 11, 15, 20, 26, 33, 41} (indices 0 through 8). A binary search is performed for the target value 20. The search uses the…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1040

Multiple choice Using Text Files
A text file "items.txt" contains the following lines, one per line. apple,3 banana,5 cherry,2 Assume the file is opened successfully and the java.util.Scanner…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1,031 of 1,079
Page 104 of 108