我已经有几年没做过java了。我想有一种更好的方式来写这个,不确定如何在谷歌上搜索这个问题。
boardSpots[0][1] = new Pawn();
boardSpots[1][1] = new Pawn();
boardSpots[2][1] = new Pawn();
boardSpots[3][1] = new Pawn();
boardSpots[4][1] = new Pawn();
boardSpots[5][1] = new Pawn();
boardSpots[6][1] = new Pawn();
boardSpots[7][1] = new Pawn();发布于 2014-02-05 06:10:51
for (int i = 0; i < 8; i++) {
boardSpots[i][1] = new Pawn();
}发布于 2014-02-05 06:13:44
使用嵌套的for循环:
for (int i = 0; i < boardSpots.length; i++) {
for (int j = 0; j < boardSpots[i].length; j++) {
boardSpots[i][j] = new Pawn();
}
}Check this great source out on loops in Java.
https://stackoverflow.com/questions/21564549
复制相似问题