Frequency Code Problem

Ok the program I have to write has to let the user input a String and then count the frequency of each letter, not case sensitive. I'm curious as to how I would code a method that counts the frequency of each letter without declaring a variable for each letter and running an if statement for all 26 letters. Thanks

Comments

  • : Ok the program I have to write has to let the user input a String and then count the frequency of each letter, not case sensitive. I'm curious as to how I would code a method that counts the frequency of each letter without declaring a variable for each letter and running an if statement for all 26 letters. Thanks
    :
    I would use an array to store all the counts. Then use a for-loop to scan the string and count all the characters. Finally calculate the frequency using that array and the length of the string.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion