public class MatrixStuff {
  
  /**
   * Read in 9 command-line ints and put them into a
   * 3x3 array
   */
  public static void main(String[] args) {
    if (args.length >= 9) {
      int[][] iTable= new int[3][3];
      
      // rows  0..i-1 have been read in
      for (int i= 0; i != iTable.length; i++) {
        
        // elements 0..j-1 of row i have been read in
        for (int j= 0; j != iTable[i].length; j++) {
          
          //
          // *  *  *
          // *  *  *
          // *  *  *
          //
          // Fool around with the 3x3 matrix of * and decide that
          // iTable[i][j] is the i*3+j element of args
          //
          iTable[i][j]=
            Integer.parseInt(args[i*3 + j]);
        }
      }
      
      // print out what we've got
      printIntTable(iTable);

      System.out.println("Now transposed:");
      
      // rows 0..i-1 have been swapped with columns
      // 0..i-1 (but there's a bug...)
      for (int i= 0; i != iTable.length; i++) {
        for (int j= 0; j != iTable[i].length; j++) {
          int swap= iTable[i][j];
          iTable[i][j]= iTable[j][i];
          iTable[j][i]= swap;
        }
      }
      
      // print out the table we hope is transposed
      printIntTable(iTable);
    }
  }
  
  
  /**
   * print a 2-dimensional int table
   */
  private static void printIntTable(int[][] table) {
    for (int i= 0; i != table.length; i++) {
      for (int j= 0; j != table[i].length; j++) {
        System.out.print(table[i][j] + " ");
      }
      System.out.println("");
    }
  }
}