1
나는 자바에서 내 2 차원 배열에 값을 할당하는 데 문제가 있습니다. 코드의 마지막 줄, theGrid[rowLoop][colLoop] = 'x';
는 ArrayIndexOutOfBoundsException
오류를 던지고있다. 누군가 이것이 왜 일어나는지 설명해 주시겠습니까?자바 2 차원 배열에 값을 할당 할 수 없습니다 -는, ArrayIndexOutOfBoundsException
이 내 코드는 ...
public class Main {
public static char[][] theGrid;
public static void main(String[] args) {
createAndFillGrid(10,10);
}
public static void createAndFillGrid(int rows, int cols) {
theGrid = new char[rows][cols];
int rowLoop = 0;
for (rowLoop = 0; rowLoop <= theGrid.length; rowLoop++) {
int colLoop = 0;
for (colLoop = 0; colLoop <= theGrid[0].length; colLoop++) {
theGrid[rowLoop][colLoop] = 'x';
}
}
}
}
! 그리고 그것은 정말 고마워요! 기꺼이 도와 – Marshma11ow
@marsh. 시스템에서 허용되면이 대답을 수락하는 것을 잊지 마십시오. – jjnguy