?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Recursive Method Equivalence

APCSA-DPCVYN

Consider the following method.

public static int mystery(int x)
{
    if (x <=1)
         return 3;
    else
         return 3 * mystery(x-1);
}

If q > 0 and q is initialized and defined as an int, which is the following is returned as a result of the call mystery(q)?

A

$3^q$

B

$3 ^{(q-1)}$

C

$(3^q) - 1$

D

$q^3$

E

$3q$