Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Counting syllables

807591Apr 3 2008 — edited Apr 5 2008
In order to count the syllables in the text one counts the vowels. I have done this as follows:

//count the vowels(including y)in the extract,vowels represent the syllables
for (int i=0;i<extract.length();i++)
{

char letter=extract.charAt(i);

if((letter=='a')||(letter=='A')||
(letter=='e')||(letter=='E')||
(letter=='i')||(letter=='I')||
(letter=='o')||(letter=='O')||
(letter=='u')||(letter=='U')||
(letter=='y')||(letter=='Y'))
{
syllableCount++;
}
}

If a word has an 'e' on the end like 'rage' then it must not be included in the syllable count. I am having problems with this part. I have tried the following but it does not work:

for (int i=0;i<extract.length();i++)
{

char endLetter=extract.charAt(i);
char endLetter2=extract.charAt(i-1);
if ((endLetter==' ')&&(endLetter2=='e'))

{
syllableCount--;
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 3 2008
Added on Apr 3 2008
56 comments
2,135 views