这个问题涉及我的二维数组显示,目前看起来像这样。二维数组显示
A B C D
1: 0 0 0 0
2: 0 0 0 0
3: 0 0 0 0
我试图让位置(0,0)更改为数字1,因为这将是我的计数的开始。
然而,它不会改变,并保持为零,这是我的代码。
int[][] chessBoard = new int[3][4];
int rowhead = 1;
TextIO.put(" ");
for (int col = 0; col < chessBoard[0].length; col++)
TextIO.putf("%4s",((char) ('A' + col)));
TextIO.putln();
for (int [] row:chessBoard){
TextIO.put(rowhead++ + ":");
for (int griddisplay:row)
TextIO.putf("%4d", griddisplay);
TextIO.putln();
chessBoard [0][0] = 1;
现在,这使我的坐标(0,0-)显示为零,但是如果我改变这个 棋盘[0] [0] = 1; 至此 chessBoard [1] [0] = 1;
那么,网格也相应变为
A B C D
1: 0 0 0 0
2: 1 0 0 0
3: 0 0 0 0
我要去哪里错了?
似乎你要更改之前打印? –
什么是TextIO?此代码不完整,并且缩进表示您可能不理解for循环的范围。 –
你可以发布更多的代码吗? – sebenalern