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,591–2,600 of 2,811
  1. 2591
  2. 2592
  3. 2593
  4. 2594
  5. 2595
  6. 2596
  7. 2597
  8. 2598
  9. 2599
  10. 2600

Question 2591

Multiple choice Unit 4: Data Collections

Consider the following methods. What is printed?

public static int sumDigits(int n) {
    if (n < 10) { return n; }
    return n % 10 + sumDigits(n / 10);
}

public static int digitalRoot(int n) {
    int s = sumDigits(n);
    if (s < 10) { return s; }
    return digitalRoot(s);
}

System.out.println(digitalRoot(9999));
Pick an answer, then check it. The solution opens in a window.

Question 2592

Multiple choice Unit 4: Data Collections

After one pass of this code, what is arr[arr.length - 1]?

int[] arr = {2, 5, 1, 8, 3};
for (int i = 0; i < arr.length - 1; i++) {
    if (arr[i] > arr[i + 1]) {
        int temp = arr[i];
        arr[i] = arr[i + 1];
        arr[i + 1] = temp;
    }
}
Pick an answer, then check it. The solution opens in a window.

Question 2593

Multiple choice Unit 4: Data Collections

What is printed?

ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 1; i <= 6; i++) {
    list.add(i * i);
}
// list = [1, 4, 9, 16, 25, 36]
for (int i = list.size() - 1; i >= 1; i -= 2) {
    list.set(i, list.get(i) - list.get(i - 1));
}
System.out.println(list);
Pick an answer, then check it. The solution opens in a window.

Question 2594

Multiple choice Unit 4: Data Collections
int[] arr = {4, 7, 2};…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2595

Multiple choice Unit 4: Data Collections
int[] arr = new int[3];…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2596

Multiple choice Unit 4: Data Collections
int[] arr = null;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2597

Multiple choice Unit 4: Data Collections
int[] arr = new int[3];…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2598

Multiple choice Unit 4: Data Collections
Integer[] arr = new Integer[3];…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2599

Multiple choice Unit 4: Data Collections
ArrayList<Integer> list = null;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2600

Multiple choice Unit 4: Data Collections
ArrayList<Integer> list = new…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2,591 of 2,811
Page 260 of 282