Write the Java code of the method Transpose2D that takes one 2-dimentional array (matrix) A and returns one 2-dimentional array B that is transpose of matrix A. (assume that all the rows are of the same length)
and this my answer
is method correct or there an another way to do itpublic int[][] transpose (int[][] array) { if (array == null || array.length == 0)//empty or unset array, nothing do to here return array; int width = array.length; int height = array[0].length; int[][] array_new = new int[height][width]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { array_new[y][x] = array[x][y]; } } return array_new; }