944,216 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2262
  • Java RSS
Sep 3rd, 2004
0

wordcount

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
copycat is offline Offline
4 posts
since Aug 2004
Sep 3rd, 2004
0

Re: wordcount

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ranyodh is offline Offline
2 posts
since Sep 2004
Sep 3rd, 2004
0

Re: wordcount

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.
Team Colleague
Reputation Points: 45
Solved Threads: 56
Unauthenticated Liar
nanosani is offline Offline
1,767 posts
since Jul 2004
Sep 4th, 2004
0

Re: wordcount

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;
}
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
copycat is offline Offline
4 posts
since Aug 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Mortgage Calculation
Next Thread in Java Forum Timeline: Pass XML file contents to a hash table.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC