Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 初始化数组元素范围的更优雅的方法_Java - Fatal编程技术网

Java 初始化数组元素范围的更优雅的方法

Java 初始化数组元素范围的更优雅的方法,java,Java,我已经有好几年没有使用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]

我已经有好几年没有使用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();
for(int i=0;i<8;i++){
boardSpots[i][1]=新典当();
}
用于(int i=0;i<8;i++){
boardSpots[i][1]=新典当();
}
用于(int i=0;i<8;i++){
boardSpots[i][1]=新典当();
}
用于(int i=0;i<8;i++){
boardSpots[i][1]=新典当();
}

为循环使用嵌套的

for (int i = 0; i < boardSpots.length; i++) {
    for (int j = 0; j < boardSpots[i].length; j++) {
        boardSpots[i][j] = new Pawn();
    }
}
for(int i=0;i

循环使用嵌套的

for (int i = 0; i < boardSpots.length; i++) {
    for (int j = 0; j < boardSpots[i].length; j++) {
        boardSpots[i][j] = new Pawn();
    }
}
for(int i=0;i

循环使用嵌套的

for (int i = 0; i < boardSpots.length; i++) {
    for (int j = 0; j < boardSpots[i].length; j++) {
        boardSpots[i][j] = new Pawn();
    }
}
for(int i=0;i

循环使用嵌套的

for (int i = 0; i < boardSpots.length; i++) {
    for (int j = 0; j < boardSpots[i].length; j++) {
        boardSpots[i][j] = new Pawn();
    }
}
for(int i=0;i

您不能在循环中创建它们吗?删除问题?:现在太晚了,我要做的就是处理这些问题。你能不能在一个循环中创建它们?删除这个问题现在太晚了,我要做的就是处理这些问题。你能不能在一个循环中创建它们?删除这个问题现在太晚了,我要做的就是处理这些问题。你能不能在一个循环中创建它们?删除这个问题托托现在迟到了,我只能忍受耻辱了