Posted by: Sourav | July 7, 2014

Find frequency of a digit in Java


import java.util.*;
class frequency{
    public static void main(String args[])
    {
       
        String n;
        char m;
        int counter=0;
        Scanner in = new Scanner(System.in);
       
        System.out.println(“input the number”);
       
        n = (in.next());
       
      //  System.out.println(n);
       
         int lengthnumber=n.length();
         //System.out.println(lengthnumber);
          for(int i=0;i<=(lengthnumber-1);i++)
            {
            m=(n.charAt(i));
            
                  for(int j=0;j<=(lengthnumber-1);j++)
                  {
                     
                      if(m==n.charAt(j))
                      {
                  counter=counter+1;
                
                }
               
            }
           
            System.out.println(“the character “+m+ ” is present in the given string “+n+”the frequency is “+ counter);
                counter=0;
           
    }
   
  
   
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: