need a little help. In the program I'm working on we are supposed to read in a text file titled prog2.dat whose contents are to represent the hours worked by 10 employees. Here is what the file looks like.
10
8 4 7 3 8 6 3
2 7 6 3 5 2 1
1 2 3 8 6 4 4
3 2 8 8 8 5 1
4 3 2 1 3 8 6
8 5 6 7 5 5 4
1 8 7 4 2 8 6
1 5 4 6 5 3 3
4 3 2 1 2 3 4
1 8 7 6 5 6 5
When the file is read in, it's to be stored in a 2D array, this is where I'm having trouble. My experience with 2D arrays is very minimal and I've never loaded one from a file before.
That's not the end of the program, but everything else is stuff that I know how to do so shouldn't be a problem, it's just getting to that point.
Here is the code I have so far.
import java.util.Scanner;
public class Program2 {
public static void main(String[] args) {
int[][] hoursArray = new int[i][j];
int employeeNum;
int i = 0;
int j = 0;
java.io.File file = new java.io.File("../instr/prog2.dat");
Scanner fin = new Scanner(file);
employeeNum = fin.nextInt();
while (fin.hasNextLine && i < hoursArray.length) {
hoursArray[i] = fin.nextInt();
i++;
}
I know this is incomplete, but that's what I have so far. Any help would be greatly appreciated.