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 131–140 of 140
  1. 131
  2. 132
  3. 133
  4. 134
  5. 135
  6. 136
  7. 137
  8. 138
  9. 139
  10. 140

Question 131

Multiple choice Recursion
Consider the following recursive method.
public static int mystery(int n)
{
    if (n <= 1)
    {
        return n;
    }
    return n + mystery(n / 2);
}
What value is returned by the call mystery(20)?
Pick an answer, then check it. The solution opens in a window.

Question 132

Multiple choice Recursion
Consider the following recursive method.
public static int digitCount(int n)
{
    if (n < 10)
    {
        return 1;
    }
    return 1 + digitCount(n / 10);
}
What value is returned by the call digitCount(84263)?
Pick an answer, then check it. The solution opens in a window.

Question 133

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

Question 134

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 135

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

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 136

Multiple choice Recursion
Consider the following method. public static int f(int n) { if (n < 10)…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 137

Multiple choice Recursion
Consider the following method.
public static int g(int n)
{
    if (n == 1)
        return 1;
    if (n % 2 == 0)
        return g(n / 2);
    return 1 + g(n - 1);
}
What value is returned by g(12) ?
Pick an answer, then check it. The solution opens in a window.

Question 138

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

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 139

Multiple choice Recursion
Consider the following recursive method. public static int recur(int n) { if (n < 3) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 140

Multiple choice Recursion

Consider the following recursive method.

public static int score(int[] arr, int k)
{
    if (k >= arr.length)
    {
        return 0;
    }

    int rest = score(arr, k + 2);

    if (arr[k] % 2 == 0)
    {
        return rest + arr[k];
    }
    return rest - arr[k];
}

What value is returned by the following code?

int[] values = {5, 2, 4, 7, 6};
score(values, 0);
Pick an answer, then check it. The solution opens in a window.
Question 131 of 140
Page 14 of 14