title: String index is out of range
body: <pre><code>import java.io.*;
  public class Program
  {
      public static void main(String args[])throws IOException
      {
          InputStreamReader isr = new InputStreamReader (System.in);
          BufferedReader br = new BufferedReader (isr);
          int i, len;
          char ch;
          String rev = "";
          System.out.println("Enter a String:");
          String str = br.readLine();
          len = str.length();
          for(i=len; i&gt;=0; i--)
          {
              ch = str.charAt(i);
              rev = rev + ch;
          }
          System.out.println("Reversed String is: " +rev);
      }
  }    
  </code></pre>
  
  <p>The program works fine until I press enter after the input.
  e.g. 
  Enter a String:</p>
  
  <p>java</p>
  
  <pre><code>Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 5
  at java.lang.String.charAt(String.java:658)
  at Program.main(Program.java:16)
  Java Result: 1
  </code></pre>
  
  <p>I tried compiling it in NetBeans. Please explain.</p>