?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Recursive Method Using Arithmetic Functions

APCSA-LPYETY

Given the following method:

public static int recur(int a)
{
    if(a == 0)
        return 0;
    else
        return recur(a-1) + a * (a-1);
}

What will be output to the console when this statement is executed?

System.out.println(recur(4));
A

40

B

20

C

18

D

12

E

6