| | |
wordcount
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2004
Posts: 2
Reputation:
Solved Threads: 0
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
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
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.
•
•
Join Date: Aug 2004
Posts: 4
Reputation:
Solved Threads: 0
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;
}
}
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;
}
}
![]() |
Similar Threads
- Code Snippet: Wordcount similar to Unix WC (Python) (Python)
- Having difficulty with a WordCount Program (Java)
- Ideas needed for problem with trailing whitespaces (C++)
- Getting words (PHP)
Other Threads in the Java Forum
- Previous Thread: Mortgage Calculation
- Next Thread: Pass XML file contents to a hash table.
| Thread Tools | Search this Thread |
actuate android api applet application applications array arrays automation balls bank binary bluetooth business chat class classes clear client code codesnippet collections component coordinates database defaultmethod development dice dragging ebook eclipse educational error formatingtextintooltipjava fractal game givemetehcodez graphics gui hql html ide image infinite ingres input integer internet invokingapacheantprogrammatically j2me java javaprojects jni jpanel jtextarea julia linux list loop looping map method methods mobile mysql netbeans newbie openjavafx parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms sort sorting sql sqlserver state storm string sun superclass swing swt text-file threads tree websites windows






