Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
hard Solved by 1 students

Recursive Character Counting

Mark
< Prev
Next >

What is printed when the following program is executed?

public class Main {
    public static int countChar(String s, char c) {
        if(s.length() == 0)
            return 0;
        int count = (s.charAt(0) == c) ? 1 : 0;
        return count + countChar(s.substring(1), c);
    }
    public static void main(String[] args) {
        System.out.println(countChar("banana", 'a'));
    }
}
A

3

B

2

C

4

D

0

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

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

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