i am trying to use recursion to find the occurence of a specific character in an array of characters
public class CharacterCounter
{
public static void main(String [] args)
{
char test[] = {'a', 'b', 'a', 'c', 'd', 'a', 'e', 'a', 'f', 'g', 'h', 'a', 'i', 'a'};
char searchChar = 'a';
System.out.println(characterCounter(test, searchChar, test.length-1));
}
private static int characterCounter(char[] t, char sc, int index)
{
int count = 0;
if(t.length < 0)
return count;
else
{
if(t[index] == sc)
return count++;
else
return characterCounter(t, sc,index-1);
}
}
}
any help or suggestions would be appreciated.. thanks