I am developing a student project and need to write a function to count syllables in word. The function like int syllables(String word).
How to count syllables in word using Java? Any suggestions?
The provided rules are:
0. To count the number of syllables you should use letters a, e, i, o, u, y as vowels.
1. Count the number of vowels in the word.
2. Do not count double-vowels (for example, "rain" has 2 vowels but is only 1 syllable)
3. If the last letter in the word is 'e' do not count it as a vowel (for example, "side" is 1 syllable)
4. If at the end it turns out that the word contains 0 vowels, then consider this word as 1-syllable.
I had already write the function but I think it is not optimal. So I just would like to see other possible solutions. If any.