title: string index out of bounds error in java (charAt)
body: <p>Quick question. I have this code in a program:</p>
  
  <pre><code>input = JOptionPane.showInputDialog("Enter any word below")
  int i = 0;  
  for (int j = 0; j &lt;= input.length(); j++)  
  {
      System.out.print(input.charAt(i));  
      System.out.print(" "); //don't ask about this.  
      i++;
  }   
  </code></pre>
  
  <ul>
  <li>Input being user input</li>
  <li><code>i</code> being integer with value of 0, as seen</li>
  </ul>
  
  <p>Running the code produces this error:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 6<br>
    at java.lang.String.charAt(Unknown Source)<br>
    at program.main(program.java:15)</p>
  </blockquote>
  
  <p>If I change the <code>charAt</code> <code>int</code> to 0 instead of <code>i</code>, it does not produce the error...<br>
  what can be done? What is the problem?</p>