wordcount

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2004
Posts: 4
Reputation: copycat is an unknown quantity at this point 
Solved Threads: 0
copycat copycat is offline Offline
Newbie Poster

wordcount

 
0
  #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
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 2
Reputation: ranyodh is an unknown quantity at this point 
Solved Threads: 0
ranyodh ranyodh is offline Offline
Newbie Poster

Re: wordcount

 
0
  #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 Quick reply to this message  
Join Date: Jul 2004
Posts: 1,749
Reputation: nanosani is an unknown quantity at this point 
Solved Threads: 54
Team Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: wordcount

 
0
  #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 Quick reply to this message  
Join Date: Aug 2004
Posts: 4
Reputation: copycat is an unknown quantity at this point 
Solved Threads: 0
copycat copycat is offline Offline
Newbie Poster

Re: wordcount

 
0
  #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 Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC