【发布时间】:2013-11-22 13:37:29
【问题描述】:
我将如何设计这样的东西,在 java 中使用 2D 数组?
A B C
15 15 200
20 20 200
25 25 200
30 30 200
35 35 200
40 40 200
45 45 200
50 50 200
55 55 200
60 60 200
int[] A = { 15, 20, 25, 30, 35, 40, 45, 50, 55, 60 };
int[][] name = new int[3][10];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 10; j++) {
name[i][j] = A[i]; // this prints out fine
name[i][j] = A[i]; // this also prints out fine
name[i][j] = 200; // but when I put this piece of code, it doesn't print the two
//above ones but instead it prints 200 on a 10 row by 3` column table.
for (int j = 0; j < 10; j++)
System.out.println(name[0][j] + " " + name[1][j] + " " + name[2][j]);
}
}
}
一切正常,但“name[i][j] = 200;”当我放这个时,它只打印这个而不是别的
【问题讨论】:
-
它的意思是 10 x 3(10 行和 3 列),第一行应该包含 15 15 200,第二行应该包含 20 20 200,第三行应该包含 25 25 200等等
-
请不要将您的问题编辑为非问题。即使您的问题已经解决,它可能仍然对其他人有用。我回滚了一些编辑。
标签: java arrays multidimensional-array 2d