title: exception in thread main java.lang.StringIndexOutOfBoundsException: String index out of range: 6
body: <p>so i am trying to wright a program to Print a word with all of the vowels replaced with $.
  in java.</p>
  
  <p>i keep getting this error <code>exception in thread main java.lang.StringIndexOutOfBoundsException: String index out of range: 6</code> when i run it, it compiles fine.
  here's the code.</p>
  
  <pre><code>import java.util.*;
  
  public class SummerFour
  {
      public static void main(String[] args)
      {
          Scanner keyboard = new Scanner(System.in);
  
          int cnt = 0;
          String word;
          String output = "";
          char letter = 'x';
          System.out.print("enter word to test: ");
          word = keyboard.nextLine();
  
          do {
  
              cnt++;
              letter = word.charAt(cnt - 1);
  
              if (letter == 'a' || letter == 'i' || letter == 'e' || letter == 'u' || letter == 'o')
              {
                  letter = '$';
              }
          }
          while (cnt &lt;= word.length());
  
          System.out.println(word);
      }
  }
  </code></pre>