I am trying to read in data from a text file and put it into a 2d array. I have the text file and I have tested my program and know that it reads the data but the following loop exits whenever I try to put the data into my array.
for(int i = 0; i<9; i++){
for(int j = 0; j<9; j++){
System.out.print("hey");
grid[i][j] = file.nextInt();
}
}
Any help would be appreciated.
[edit]
Sorry for the initial lack of information i only posted the snippet which i was having trouble with.
grid is initialized higher up in the code as int[][] grid; and the file is a .txt that contains each number that is meant to be in the grid seperated by a single space.
int[][] grid;doesn’t actually allocate any memory, maybe you wanted