Here you can find the source of transpose(int[][] matrix)
public static int[][] transpose(int[][] matrix)
//package com.java2s; //License from project: Open Source License public class Main { public static int[][] transpose(int[][] matrix) { if (matrix.length == 0 || matrix[0].length == 0) return matrix; int[][] result = new int[matrix[0].length][matrix.length]; for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[0].length; j++) { int delta = (int) ((Math.random() * 20 - 10) / 9); delta *= (int) (Math.random() * 3); result[j][i] = matrix[i][j] + delta; }//from ww w . j a v a 2s . c om } return result; } }