Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to write a method that computes how often each letter A-Z or a-z occurs in a string. Don't distinguish between upper- and lowercase letters. Return an array of length 26. The ith element contains the number of times that the letter 'a' + i or 'A' + i occurs in the string. The string may contain other characters that you should simply skip.

I have the following code:

public class Letters
{
   /**
      Counts the frequencies of letters A-Za-z in a string
      @param str a string
      @return an array of 26 counts. The i-th count is the number of occurrences
      of 'A' + i or 'a' + i.
   */
   public int[] letterFrequencies(String str)
   {
      ........

   }
}
Posted
Updated 9-Apr-12 19:26pm
v5

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
 
Share this answer
 
funny. come on, serious, this is a classic home work.

I can tell you that you should use this class: java.lang.String - javadoc[^]

This might also be helpfull - StringTokenizer[^]

Read. Think about it. That's 90% of developing software. The coding is just the translation of your wicked thoughts into the machine.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900