Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting Letter Frequency

Status
Not open for further replies.

supervi

MIS
Mar 22, 2003
61
0
0
CA
Hello,
I need to write a java program that will take a string input from a user and output the frequency of each letter in the word. I could use long case statements but I think there might be a more efficient way of doing this.

When the user inputs a string, does each letter correspond to an integer value?

Thanks in advance for any guidance.

Puzzled.
 
Convert the String to a char[] array, then loop the array, incrementing a count for each occurrence of your desired char.

--------------------------------------------------
Free Database Connection Pooling Software
 
I'm not sure if you mean the number of ocurrences of each letter or the audio frequency when you pronounce it.

Anyway, to get that value:

Code:
String myString = "someChars";
for (int i=0; i<myString.size(); i++)
  System.out.println((int) myString.charAt(i));

Cheers,

Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top