使用
Arrays.
deepToString()
用于打印多维数组:
import java.util.Arrays;
class Main {
public static int[][] doubleMat(int[][] mat) {
int row = mat.length;
int col = mat[0].length;
int[][] num = new int[row][col];
for (int x = 0; x < row; x++) {
for (int y = 0; y < col; y++) {
num[x][y] = mat[x][y] * 2;
}
}
return num;
}
public static void main(String[] args) {
int[][] mat = { { 45, 101, 87, 12, 41, 0 }, { 12, 8, 12, 8, 15, 841 }, { -12, -1, -741, -1, 0, 74 } };
System.out.printf("Before doubleMat: %s%n", Arrays.deepToString(mat));
System.out.printf("After doubleMat: %s%n", Arrays.deepToString(doubleMat(mat)));
}
}
输出:
Before doubleMat: [[45, 101, 87, 12, 41, 0], [12, 8, 12, 8, 15, 841], [-12, -1, -741, -1, 0, 74]]
After doubleMat: [[90, 202, 174, 24, 82, 0], [24, 16, 24, 16, 30, 1682], [-24, -2, -1482, -2, 0, 148]]