这是我的代码:
public static int[][] arraytriangle(int lines){
int[][] tri = new int[lines][];
int c = 1; // incremented number to use as filler
for (int i = 0; i < lines; i++){
for (int j = 0; j <= i; j++){
tri[i] = new int[i+1]; // defines number of columns
tri[i][j] = c;
System.out.print(c + " ");
c++; // increment counter
}
System.out.println(); // making new line
}
System.out.println(Arrays.deepToString(tri));
return tri;
arraytriangle(3) 给出:
1
2 3
4 5 6
[[1], [0, 3], [0, 0, 6]]
所以程序打印正确(1,2,3...),但是当我使用 deepToString 时矩阵值不正确。是什么赋予了?