Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: find frequency of characters using static method

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default find frequency of characters using static method

    import java.io.*;
    import java.util.*;

    class countfreq
    {
    public static void main(String s[]) throws Exception
    {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    System.out.print(" enter string ");
    System.out.println();
    String str=br.readLine();
    String st=str.replaceAll(" ", "");

    char[] demo=st.toCharArray();
    public static int sequenceCount(String str)
    {
    for(int counter=0;counter<demo.length;counter++)
    {
    char ch=demo[counter];
    int count=0;
    for ( int i=0; i<demo.length; i++){
    if (ch== demo[i])
    count++;
    }

    boolean flag=false;
    for(int j=counter-1;j>=0;j--)
    {
    if(ch==demo[j])
    flag=true;
    }
    if(!flag)
    {

    System.out.println("Character :"+ch+" occurs "+count+" times ");

    }
    }
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: find frequency of characters using static method

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: find frequency of characters using static method

    And ask a question or describe what you need help with or don't understand. Like when my 3-year old would just point at something and grunt or whine, we'd say, "Use your words." Try that.

Similar Threads

  1. How to call a static method within a static method in the same class?
    By EDale in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 10th, 2013, 04:13 AM
  2. Replies: 6
    Last Post: May 3rd, 2013, 04:25 PM
  3. Replies: 1
    Last Post: April 3rd, 2012, 06:32 AM
  4. Finding frequency and probability of characters in a string
    By Aberforth in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 31st, 2010, 02:02 AM
  5. Replies: 10
    Last Post: September 6th, 2010, 04:48 PM