public class Environment {
//variables
RoundingStage[][] land;
int horizontalStreets;
int verticalStreets;
public Environment(RoundingStage[][] grid) {
this.horizontalStreets = grid.length;
this.verticalStreets = grid[0].length;
land = new RoundingStage[horizontalStreets][verticalStreets];
for (int i = 0 ; i <= horizontalStreets ; i++)
for (int j = 0 ; j <= verticalStreets ; j++)
land[i][j] = grid[i][j];
}
public Environment(Environment env) {
this.horizontalStreets = env.horizontalStreets;
this.verticalStreets = env.verticalStreets;
land = new RoundingStage[horizontalStreets][verticalStreets];
for (int i = 0 ; i <= horizontalStreets ; i++)
for (int j=0 ; j <= verticalStreets ; j++)
land[i][j] = env.land[i][j];
}
Может кто-нибудь сказать мне, почему я получаю ArrayOutOfBound, когда я использую эту функцию, я пробовал все комбинации +1, -1, мне нужна помощь, пожалуйста: DArrayIndexOutOfBounds в конструкторе класса
public RoundingStage valueInPosition(int rHor, int rVer) {
return land[rHor-1][rVer-1];
}
Извините, я не понял. Не могли бы вы лучше объяснить? –
От 0 до n есть n + 1 элементов, поэтому вы должны зацикливаться от 0 до n - 1. Чтобы быть ясным, замените все ваши '<=' на '<' в ваших условиях цикла – Dici
Im все еще получаю OutOfBounds в строке valueInPosition , Его за пределами: -1 –