/**
 * Demonstrates more than one way to print a string diagonally,
 * all in uppercase.
 *
 * @author Zach Tomaszewski
 * @version 18 Mar 2008
 */
public class PrintDiagonally {

  /**
   * Shows results for each method in this class.
   */
  public static void main(String[] args) {
    String hello = "Hello.";
    PrintDiagonally.usingNestedFors(hello);
    PrintDiagonally.usingSpaceVariable(hello);
    PrintDiagonally.usingMatrix(hello);
  }


  public static void usingNestedFors(String str) {
    //indents each line using an inner for loop
    str = str.toUpperCase();
    for (int i = 0; i < str.length(); i++) {  //each character
      for (int j = 0; j < i; j++) {  //number of spaces on this line
        System.out.print(" ");
      }
      System.out.println(str.charAt(i));
    }
  }

  public static void usingSpaceVariable(String str) {
    //indents each line using a string of space that grows each time
    str = str.toUpperCase();
    String space = "";
    for (int i = 0; i < str.length(); i++) {  //each character
      System.out.print(space);
      System.out.println(str.charAt(i));
      space += " ";  //grow space variable by one space
    }
  }

  public static void usingMatrix(String str) {
    //prints out a 2D matrix of str, printing spaces except
    //where the two dimensions intersect on the diagonal.
    str = str.toUpperCase();
    for (int y = 0; y < str.length(); y++) { //print rows
      for (int x = 0; x < str.length(); x++) { //print columns
        if (x == y) {
          System.out.print(str.charAt(x));
        }else {
          System.out.print(" ");
        }
      }
      System.out.println();  //end row
    }
  }

}
