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

Recommended Answers

All 3 Replies

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 == 'a') {
aCount += 1;
}
if(brockenString == 'e') {
eCount += 1;
}
if(brockenString == 'i') {
iCount += 1;
}
if(brockenString == 'o') {
oCount += 1;
}
if(brockenString == 'u') {
uCount += 1;
}
}


// Now you got the counts for each letters

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.

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 == 'a') {//i don't readily understand can example?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.