WHAT'S NEW?

Finding Repetition of a character in a string

public class CharacterFinder 
{

public static void main(String[] args) 
{
int mCounter=0;
String name="Tommy";

for (int i=0;i<name.length() ;i++ )
{
char c=name.charAt(i);
if (Character.toString(c).equalsIgnoreCase("m"))
{
mCounter++;
}
}

System.out.println("Word m is repeated "+mCounter+" times in the given string");
}
}

0 comments:

Post a Comment