AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Recursive Method Which Uses Modulus Arithmetic

APCSA-XYTGV4

Consider the following method.

public static int mystery(int x)
{
    if (x <= 0)
        return 0;
    if (x%2 == 0)
        return x + mystery(x-2);
    else
        return x + mystery(x-1);
}

Which of the following is returned when mystery(9) is called?

A

25

B

26

C

27

D

28

E

29