// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class Transpose {
   public static int[][] transpose(int[][] a) {
      int[][] res = new int[a[0].length][a.length];
      for(int row = 0; row < res[0].length; row++) {
         for(int col = 0; col < res.length; col++) {
            res[col][row] = a[row][col];
         }
      }
      return res;
   }
   public static void main(String[] args) {
      int[][] a = new int[3][2];
      for(int row = 0; row < a[0].length; row++) {
         for(int col = 0; col < a.length; col++) {
            a[col][row] = (col + 1) * (row + 1);
         }
      }
      for(int row = 0; row < a[0].length; row++) {
         for(int col = 0; col < a.length; col++) {
            System.out.print(" " + a[col][row]);
         }
         System.out.println();
      }
      int[][] b = transpose(a);
      for(int row = 0; row < b[0].length; row++) {
         for(int col = 0; col < b.length; col++) {
            System.out.print(" " + b[col][row]);
         }
         System.out.println();
      }
   }
}
