Finding MAX value from "file.txt"
I'm trying to find the MAX value for...let's say 600 integers from "file.txt" by using an array. And oh, I've only learn until array so far.
"file.txt" contains like this:
2.3
3.4
6.0
...
Here's what I have so far:
Code:
public static void main(String[] args)throws FileNotFoundException{
Scanner console = new Scanner(System.in);
System.out.print("Please enter your file name: ");
String name = console.nextLine();
Scanner input = new Scanner(new File(name));
int totalNum = input.nextInt();
System.out.println("There are " + totalNum + " in your file.");
double[] count = new double[1000]; //Putting list of integers from file into an array?
int i = 1;
while (input.hasNextDouble()){
count[i++] = input.nextDouble();
}
double max = getMaximum(count); //Calling getMaximum
System.out.println("Max: " + max);
}
public static double getMaximum(double[] count){
double max = 0;
for(int i = 1; i <= count.length; i++){
if(count[i] > max){
max = input[i];
}
}
return max;
}