我该如何打印?二维阵列
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
我有这个至今:
int ROWS = 4;
int COLS = 4;
int[][] a2 = new int[ROWS][COLS];
String output = ""; // Accumulate text here (should be StringBuilder).
//... Print array in rectangular form using nested for loops.
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLS; col++) {
output += " " + a2[row][col];
}
output += "\n";
System.out.print(output);
,但它只是打印此:
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
而且我想在随意打印出来的数字。 我该怎么做?
该行ROWS ++;不应该在那里。 – 2012-02-08 12:05:55
您可以编辑您的帖子以将其删除。标签下面有一个“编辑”链接。 – Mat 2012-02-08 12:07:41
由于未在a2数组中填充值,因此您正在归零? – 2012-02-08 12:07:50