Hi, so I am supposed to read the lines from a text file, and output the data into a 2D array, I have read the lines but I am confused as to how to input the contents to the 2D array.
This is the file :
eoksibaebl
ropeneapop
mbrflaoyrm
gciarrauna
utmorapply
wnarmupnke
ngrelclene
alytueyuei
fgrammarib
tdcebykxka
My problem is how do I put these strings into the the 2d array as shown below.
public class WordFinder {
public static final int N = 10;
public static char[][] grid = new char[N][N];
public static final String GRID_FILE = "grid.txt";
public static void initGrid() {
try {
File file = new File(GRID_FILE);
Scanner scanner = new Scanner(file);
while (scanner.hasNext()) {
System.out.println(scanner.next());
}
scanner.close();
}
catch (FileNotFoundException e) {
System.out.println("File not found.");
}
}
I am quite new to JAVA, so any help would be much appriciated!