title: How to count vowels in a string?
body: <p>The objective is to count how many vowels there are in the phrase that the user inputs.
  The user will input a phrase which will be</p>
  
  <pre><code>my name is nic
  </code></pre>
  
  <p>The output will be for this example is</p>
  
  <pre><code>Vowel Count: 4
  </code></pre>
  
  <p>Now here is my code.</p>
  
  <pre><code>    import cs1.Keyboard;
  public class VowelCount {
  
      public static void main(String[] args) {
          System.out.println("Please enter in a sentence.");
              String phrase = Keyboard.readString();
              char[] phraseArray = phrase.toCharArray();
              char[] vowels = new char[4];
              vowels[0] = 'a';
              vowels[1] = 'e';
              vowels[2] = 'i';
              vowels[3] = 'o';
              vowels[4] = 'u';
              int vCount = countVowel(phrase, phraseArray, vowels);
              System.out.println("Vowel Count: " + vCount);
      }
  
      public static int countVowel(String word, char[] pArray, char[] v) {
          int vowelCount = 0;
          for (int i = 0; i &lt; word.length(); i++) {
              if (v[i] == pArray[i])
                  vowelCount++;
          }
          return vowelCount;
      }
  }
  </code></pre>
  
  <p>With my code I am getting an ArrayIndex Error. I know the fix but when I change</p>
  
  <pre><code>for (int i = 0; i &lt; word.length(); i++) {
  </code></pre>
  
  <p>to</p>
  
  <pre><code>for (int i = 0; i &lt; 5; i++) {
  </code></pre>
  
  <p>It fixes the error but does not count the vowels. It outputs </p>
  
  <pre><code>Vowel Count: 0
  </code></pre>
  
  <p>So how can I fix this problem and is there a better way to do this than the way I am attempting to do it?</p>