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,811–2,811 of 2,811
  1. 2811

Question 2811

Multiple choice Unit 4: Data Collections

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 2,811 of 2,811
Page 282 of 282