10 Duke Stars available
|
This topic has
3
replies
on
1
page.
|
|
|
|
|
|
|
|
|
how the frequency of character can be counted optimally in java? thanks
|
|
|
|
|
|
|
|
You tell us. After all, it's your homework.
db
|
|
|
|
|
|
|
|
how the frequency of character can be counted optimally in java? thanks
By iterating over the characters of the string and counting how much each character occurs.
|
|
_Anti
Posts:10
Registered: 11/7/09
|
|
|
|
|
String text="ghkhwehrgjklwheorhnfgpwjelrgjwelrg";
text=text.toLowerCase();
int charNum=26; // the number of unique characters
int[] freq=new int[charNum];
for(int i=0;i<text.length();i++) {
freq[text.charAt(i)-'a']++;
}
for(int i=0;i<charNum;i++) {
System.out.println("Frequency of " + (char) (97 + i) +": " + freq[i]);
}
|
|
|
This topic has
3
replies
on
1
page.
|
|
Back to Forum
Read the Developer Forums Code of Conduct
Email this Topic
Edit this Topic
|
|
Site Upgrade
Forums 7.1.8 was deployed Oct 26th. The release consists of minor fixes & a few enhancements.
|
|
Forums Statistics
Users Online : 29 - Guests : 131
About Sun forums
-
Sun Forums is a large collection of user generated
discussions. It is here to help you ask questions, find answers, and
participate in discussions.
Check out our guide on Getting
started with Sun Forums for a full walkthrough of how to best
leverage the benefits of this community.
|
|