public class ForDemo {
  
  /**
   * initialization;
   * while(condition) {
   *   body
   *   updatestatement
   * }
   * 
   * for(initialization; condition; update statement) {
   *   body
   * }
   * 
   * For loops are good to use when you know the range
   * and bad otherwise.
   */ 
  
  /** 
   * Return the string s with the characters reversed.
   */ 
  public static String reverse(String s) { 
    String rev = "";
    
    for (int i = 0; i < s.length(); i++) {
      rev = s.charAt(i) + rev;
    }
    
    return rev;
  }
  
  
  /**
   * Print the squares of integers in the range
   * 1 to n.
   */
  public static void printSquares(int n) {
    for (int i = 1; i <= n; i++) {
      System.out.println(i * i);
    }
  }
  
  /**
   * Return  true if the string is a palindrome (i.e.
   * its reverse is the same as itself. Otherwise, return false. 
   */
  public static boolean isPalindrome(String s) {
    for (int i = 0; i < s.length() / 2; i++) {
      if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
        return false;
      }
    }
    return true;
  }

}