I'm trying to get a 2D array out of a file and into my program. I'm not sure what the size of the 2D arrays is and it has to be sorted in descending order. If I type in a sample array into my code the for statement executes perfectly. My best frustration is getting a 2D array from another file and making my code run and execute it. Can anyone help me with this..
Code:
public class Project2 {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(new File("prog2.txt"));
int number = 0;
while (sc.hasNext()) {
sc.nextLine();
number++;
}
System.out.println(number);
This is what I have to get the file that I need. This displays the number of rows there are.
Code:
for (int i = 0; i < hours.length; i++) {
int sum = totalHours(hours, i);
System.out.println("Employee " + i + ": " + sum);
}
}
This is the for statement that well execute perfectly whenever I manually type in numbers for the 2D array.
I'm trying to get the numbers from the file to run through this for statement. I'm completely confused on how to do this and I've been stuck on this for hours now. Thank y'all in advance for all the help!