Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 10: Recursion
Start Practice TestPractice Test
About Exam
medium Solved by 1 students

Recursive Method with a Static Counter

< Prev
Next >

What is printed when the following program is executed?

public class FactorialCounter {
    static int counter = 0;
    
    public static int factorial(int n) {
        counter++;
        if(n <= 1) return 1;
        return n * factorial(n - 1);
    }
    
    public static void main(String[] args) {
        int result = factorial(4);
        System.out.println(result + " " + counter);
    }
}
A

120 5

B

24 5

C

120 4

D

24 4

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question
Mark for review

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

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