title: Counting syllables within a word
body: <p>I am looking to create a method that counts the number of syllables within a word. A syllable defined in my project as a contiguous group of vowels but not an 'e' at the end of the word. So the word 'obvious' by this definition only has 2 syllables and the string 'obstinanceeeeeee' has 3 syllables. My attempt is:</p>
  
  <pre><code>protected int countSyllables(String word)
  String input = word.toLowerCase();
      int i = input.length() - 1;
      int syllables = 0, numOfE = 0;
      // skip all the e's in the end
      while (i &gt;= 0 &amp;&amp; input.charAt(i) == 'e') {
          i--;
          numOfE++;
      }
  
      // This counts the number of consonants within a word
      int j = 0;
      int consonants = 0;
      while (j &lt; input.length()) {
          if (!isVowel(input.charAt(j))) {
              consonants++;
          }
          j++;
      }
  
      // This will return syllables = 1 if the string is all consonants except for 1 e at the end.
      if (consonants == input.length() - 1 &amp;&amp; numOfE == 1) {
          syllables = 1;
      }
  
      boolean preVowel = false;
      while (i &gt;= 0) {
          if (isVowel(input.charAt(i))) {
              if (!preVowel) {
                 syllables++;
                 preVowel = true;
              }
          } else {
              preVowel = false;
          }
          i--;
      }
      return syllables;
  }
  
  public boolean isVowel(char ch) {
     if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y') {
         return true;
     }
     return false;
  }
  </code></pre>