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.

Subtopic: Recursion Clear filter

Questions 121–130 of 140
  1. 121
  2. 122
  3. 123
  4. 124
  5. 125
  6. 126
  7. 127
  8. 128
  9. 129
  10. 130

Question 121

Multiple choice Recursion

What is the return value of f(5)?

public static int f(int n) {
    if (n <= 0) return 0;
    if (n == 1) return 1;
    return f(n - 1) + f(n - 2) + 1;
}
Pick an answer, then check it. The solution opens in a window.

Question 122

Multiple choice Recursion

What is printed?

public static int mystery(int n) {
    if (n <= 1) { return n; }
    return mystery(n - 1) + mystery(n - 2);
}
System.out.println(mystery(7));
Pick an answer, then check it. The solution opens in a window.

Question 123

Multiple choice Recursion

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 124

Multiple choice Recursion
public static int calculateValue(int n) { if (n <= 1) { return 1; } return n *…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 125

Multiple choice Recursion
public static int processValue(int n) { if (n == 0) { return 0; } return n +…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 126

Multiple choice Recursion
public static int evaluateNumber(int n) { if (n == 0) { return 1; } return 1 +…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 127

Multiple choice Recursion
public static int transformNumber(int n) { if (n == 0) { return 0; } if (n % 2 == 0) { return…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 128

Multiple choice Recursion
public static int analyzeValue(int n) { if (n == 1) { return 1; } return…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 129

Multiple choice Recursion
public static int recursiveProcess(int n) { if (n == 0) { return 0; } return…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 130

Multiple choice Recursion
Consider the following method: public static int recur(int n) { if (n <= 1) return…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 121 of 140
Page 13 of 14