User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 391,579 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,716 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1655 | Replies: 3
Reply
Join Date: Aug 2004
Posts: 4
Reputation: copycat is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
copycat copycat is offline Offline
Newbie Poster

wordcount

  #1  
Sep 3rd, 2004
Can someone help mi I need to do a word count i enter a word e.g. superboymother

it will search for the char a,e,i,o,u
and return mi

the result is:
a=0
e=2
i=o
o=2
u=o
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 2
Reputation: ranyodh is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ranyodh ranyodh is offline Offline
Newbie Poster

Re: wordcount

  #2  
Sep 3rd, 2004
here is the code...

String string = "superboymother"; // string variable contains the string that u want to search

int aCount = 0;
int eCount = 0;
int iCount = 0;
int oCount = 0;
int uCount = 0;

char[] stringBrocken = string.toCharArray();
for(int i=0; i<stringBrocken.length; i++) {
if(brockenString[i] == 'a') {
aCount += 1;
}
if(brockenString[i] == 'e') {
eCount += 1;
}
if(brockenString[i] == 'i') {
iCount += 1;
}
if(brockenString[i] == 'o') {
oCount += 1;
}
if(brockenString[i] == 'u') {
uCount += 1;
}
}


// Now you got the counts for each letters
Reply With Quote  
Join Date: Jul 2004
Location: Pakistan
Posts: 1,673
Reputation: nanosani is an unknown quantity at this point 
Rep Power: 8
Solved Threads: 49
Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: wordcount

  #3  
Sep 3rd, 2004
ranyodh you are too smart.... I was using String.indexOf() ....But your way looks better than mine if it is the matter of only a few letters or numbers.
Reply With Quote  
Join Date: Aug 2004
Posts: 4
Reputation: copycat is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
copycat copycat is offline Offline
Newbie Poster

Re: wordcount

  #4  
Sep 4th, 2004
String string = "superboymother"; // string variable contains the string that u want to search

int aCount = 0;
int eCount = 0;
int iCount = 0;
int oCount = 0;
int uCount = 0;

char[] stringBrocken = string.toCharArray();//i don't readily understand can example?
for(int i=0; i<stringBrocken.length; i++) {//i don't readily understand can example?
if(brockenString[i] == 'a') {//i don't readily understand can example?

aCount += 1;
}
if(brockenString[i] == 'e') {
eCount += 1;
}
if(brockenString[i] == 'i') {
iCount += 1;
}
if(brockenString[i] == 'o') {
oCount += 1;
}
if(brockenString[i] == 'u') {
uCount += 1;
}
}
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Java Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 10:47 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC