| preferred AP College board partner for AP classes
medium Solved by 3 students
Recursive Method Return Value
< Prev
Next >

Consider the following code segment. What value is returned by the method call tailSum(4, 0)?

public class Main {
    public static int tailSum(int n, int accumulator) {
        if(n == 0)
            return accumulator;
        return tailSum(n - 1, accumulator + n);
    }
    public static void main(String[] args) {
        System.out.println(tailSum(4, 0));
    }
}
A

7

B

8

C

4

D

10

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy