2
score
13.8K
views
no
status
CC BY-SA 3.0
Recursion to find the number of occurrences of a specified character in a string
The other answers are correct; you need to check the length of the string before calling str.substring(1) . However, you don't need another method to maintain the ct variable. Here is a Java 101 appropriate answer: