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 71–80 of 1,222
  1. 71
  2. 72
  3. 73
  4. 74
  5. 75
  6. 76
  7. 77
  8. 78
  9. 79
  10. 80

Question 71

Multiple choice Recursion
Given the following code: public static int mystery(String str) { if (str.length() == 0) return 0; else { if (str.substring(0,…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 72

Multiple choice Sorting And Searching
A recursive binary search on a sorted 10-element array uses mid=(low+high)/2 and returns −1 only…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 73

Multiple choice Sorting And Searching
How many calls to mystery occur, including the initial call, for mystery(0,4,5) with arr={1,2,3,5,7}? private int[] arr; public int mystery(int low, int high,…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 74

Multiple choice Arrays
Consider the following method. public static int mystery(int[] arr) { int x = 0; for (int k = 0; k < arr.length; k = k + 2) x = x + arr[k]; return x; } Assume…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 75

Multiple choice Arraylists
Consider the following method. public ArrayList<Integer> mystery(int n) { ArrayList<Integer> seq = new ArrayList<Integer>(); for (int k = 1; k <= n; k++)…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 76

Multiple choice Arrays
Consider the following method that is intended to return the sum of the elements in the array key. public static int sumArray(int[] key) { int sum = 0; for (int…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 77

Multiple choice Recursion
Consider the following instance variable and methods. You may assume that data has been initialized with length > 0. The methods are intended to return the…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 78

Multiple choice Arrays
Consider the following code segment. int[] arr = {7, 2, 5, 3, 0, 10}; for (int k = 0; k < arr.length - 1; k++) { if…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 79

Multiple choice Arrays
Consider the following method, isSorted, which is intended to return true if an array of integers is sorted in nondecreasing order and to return false…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 80

Multiple choice Arrays
Consider the following incomplete method that is intended to return an array that contains the contents of its first array parameter followed by the contents of…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 71 of 1,222
Page 8 of 123