title: Java - Writing a syllable counter based on specifications
body: <p><strong>Specification for a syllable:</strong></p>
  
  <p>Each group of adjacent vowels (a, e, i, o, u, y) counts as one syllable (for example, the "ea" in "real" contributes one syllable, but the "e...a" in "regal" counts as two syllables). However, an "e" at the end of a word doesn't count as a syllable. Also each word has at least one syllable, even if the previous rules give a count of zero.</p>
  
  <p><em>My countSyllables method:</em></p>
  
  <pre><code>public int countSyllables(String word) {
      int count = 0;
      word = word.toLowerCase();
      for (int i = 0; i &lt; word.length(); i++) {
          if (word.charAt(i) == '\"' || word.charAt(i) == '\'' || word.charAt(i) == '-' || word.charAt(i) == ',' || word.charAt(i) == ')' || word.charAt(i) == '(') {
              word = word.substring(0,i)+word.substring(i+1, word.length());
          }
      }
      boolean isPrevVowel = false;
      for (int j = 0; j &lt; word.length(); j++) {
          if (word.contains("a") || word.contains("e") || word.contains("i") || word.contains("o") || word.contains("u")) {
              if (isVowel(word.charAt(j)) &amp;&amp; !((word.charAt(j) == 'e') &amp;&amp; (j == word.length()-1))) {
                  if (isPrevVowel == false) {
                      count++;
                      isPrevVowel = true;
                  }
              } else {
                  isPrevVowel = false;
              }
          } else {
              count++;
              break;
          }
      }
      return count;
  }
  </code></pre>
  
  <p><em>The isVowel method which determines if a letter is a vowel:</em></p>
  
  <pre><code>public boolean isVowel(char c) {
          if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
              return true;
          } else {
              return false;
          }
      }
  </code></pre>
  
  <p>According to a colleague, this should result in 528 syllables when used on <a href="http://pastebin.com/4aXQTRWQ" rel="nofollow"><strong>this text</strong></a>, but I can seem to get it to equal that and I don't know which of us is correct. Please help me develop my method into the correct algorithm or help show this is correct. Thank you.</p>