Reputation: 534
Hi im trying to create a recursive method that returns the amount of times a character exists within a word. So far I have created a method that achieves this non-recursively, but Im having trouble thinking about how to do it recursively.
public static int count (String line, char c)
{
int charOccurences = 0;
for (int x = 0 ; x < line.length () ; x++)
{
if (line.charAt (x) == c)
{
charOccurences++;
}
}
return charOccurences;
}
Any help would be great, thanks.
Upvotes: 0
Views: 95
Reputation: 693
You're missing some logic here.
This sounds like a homework problem so I'm going to let someone else do your homework for you :)
Good luck!
Upvotes: 3