Java

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");
 }
}

Related Posts

language_img
Java

Factorial Program

Oct 4, 2013

language_img
Java

Methods

Oct 4, 2013

Table Of Contents

;