I'm having big trouble with figuring out how to read from a file using a scanner and method. Here's my outline I have:
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class ReadFile1 {
public static void main(String[] commandlineArgument) {
Integer[] array = ReadFile1.readFileReturnIntegers(commandlineArgument[0]);
ReadFile1.printArrayAndIntegerCount(array, commandlineArgument[0]);
}
public static Integer[] readFileReturnIntegers(String filename) {
Integer[] array = new Integer[1000];
//...?
return array;
}
public static void printArrayAndIntegerCount(Integer[] array, String filename) {
//...?
}
}
I'm trying to read and return an array integers with all and only the integers from my inputted file. I'm so confused with how these methods work and I have no clue on how to start reading.
Sample Output:
index = 0, element = 1877
index = 1, element = 1879
index = 2, element = 2000