title: why string length -1
body: <p>I have found the following program to check if a string is palindrome. </p>
  
  <pre><code>import java.util.Scanner;
  
  public class PalindromeString{
      public static void main(String[] args){
          Scanner in = new Scanner(System.in);
          System.out.println("Enter the string which you want to check whether that is palindrome or not: ");
          String s = in.next();
          String r = "";
          for(int i=s.length()-1; i&gt;=0; i--){
              r = r+s.charAt(i);
          }
          System.out.println("Reverse of entered string "+s+" is "+r);
          if(r.equals(s)){
              System.out.println("String "+s+" is palindrome.");
          }else{
              System.out.println("String "+s+" is not palindrome.");
          }
      }
  }
  </code></pre>
  
  <p>I did not understand why the coder initialized the loop variable <code>i</code> to <code>s.length()-1</code>. Can anyone explain me why? I have searched related content for string length but couldn't find an answer for this. </p>