Monday 11 March 2013

Count Char Occurrences in Java

public static int count_Chars(String given, char key)
{
int count = 0;
for (int i=0; i < given.length(); i++)
{
if (given.charAt(i) == key)
{
count++;
}
}
return count;
}

No comments:

Post a Comment