import java.util.Arrays;

public class TwoDStuff {
  /* prints every element row by row */
  public static void rowByRow(int [][]A) {
    for (int i = 0; i < A.length; i++) {
      // print row i
      System.out.println(Arrays.toString(A[i]));
    }
  }

  public static void rowByRowAgain(int [][]A) {
    for (int i = 0; i < A.length; i++) {
      // print row i
      for (int j = 0; j < A[i].length; j++) {
        System.out.print(A[i][j] + " ");
      }
      System.out.println();
    }
  }

  /* prints column by column
   * assuming each row has the same number
   * of columns */
  public static void colByCol(int [][]A) {
    for (int i = 0; i < A[0].length; i++) {
      for (int j = 0; j < A.length; j++) {
        System.out.print(A[j][i] + " ");
      }
      System.out.println();
    }
  }
  
  public static void main(String []args) {
    // int []A = {10, 20, 30};

    int [][]A = {
      {10, 20, 30},
      {40, 50, 60}
    };

    rowByRow(A);
    rowByRowAgain(A);
    colByCol(A);

    int [][]sq = {
      {10, 11, 12, 13},
      {20, 21, 22, 23},
      {30, 31, 32, 33},
      {40, 41, 42, 43}
    };

    printDiag(sq);
  }
  /* prints the top-left to bottom right
   * diagonal for a square matrix */
  public static void printDiag(int [][]A) {
    for (int i = 0; i < A.length; i++) {
      System.out.print(A[i][i] + " ");
    }
    System.out.println();
  }
}
