我正在嘗試打印此矩陣陣列的轉置版本,但它是打印內存位置。有關如何打印實際數組的任何輸入?轉置陣列打印不正確
這是它打印:[I @ 4b71bbc9,[I @ 17dfafd1,[I @ 5e8fce95]
import java.util.*;
class MatrixTranspose
{
public static void main (String [] args)
{
int [] [] m = {
{3, 6, 9},
{4, 1, 5},
{5, 8, 7},
};
System.out.println (Arrays.toString (transpose(m)));
}
public static int [] [] transpose (int [] [] x)
{
int start = 1;
for (int r = 0; r < x.length; r++)
{
for (int c = start; c < x[0].length; c++)
{
int temp = x[r][c];
x [r][c] = x[c][r];
x[c][r] = temp;
}
start++;
}
return x;
}
}