title: Array Index Out of Bounds Exception (Java)
body: <p>Here is my code:</p>
  
  <pre><code>public class countChar {
  
      public static void main(String[] args) {
          int i;
          String userInput = new String();
  
          userInput = Input.getString("Please enter a sentence");
  
          int[] total = totalChars(userInput.toLowerCase());
  
          for (i = 0; i &lt; total.length; i++);
          {
              if (total[i] != 0) {
                  System.out.println("Letter" + (char) ('a' + i) + " count =" + total[i]);
              }
          }
      }
  
      public static int[] totalChars(String userInput) {
          int[] total = new int[26];
          int i;
          for (i = 0; i &lt; userInput.length(); i++) {
              if (Character.isLetter(userInput.charAt(i))) {
                  total[userInput.charAt(i) - 'a']++;
              }
          }
          return total;
      }
  }
  </code></pre>
  
  <p>The program's purpose is to ask the user for a string, and then count the number of times each character is used in the string. </p>
  
  <p>When I go to compile the program, it works fine. When I run the program, I am able to enter a string in the popup box, but after I submit the string and press OK, I get an error, saying  </p>
  
  <pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 26
  at countChar.main(countChar.java:14)
  </code></pre>
  
  <p>I'm not completely sure what the problem is or how to fix it.</p>