public class Transpose {
  /** Only go half way otherwise you will transpose
   *  the array back to its original position.
   */
  public static void transpose(int[][] matrix) {
    int temp;
    for (int i = 0; i < matrix.length / 2; i++) {
      for (int j = 0; j < matrix[i].length; j++) {
      temp = matrix[i][j];
      matrix[i][j] = matrix [j][i];
      matrix[j][i] = temp;
      }
    }
  } 
  
  /** Display the matrix */
  public static void print(int [][] matrix) {
    for (int i = 0; i < matrix.length; i++) {
      for (int j = 0; j < matrix[i].length; j++) {
        System.out.print(matrix[i][j] + " ");
      }
      System.out.print("\n");
    }
  }
}
  
                                                     

