I need to find the min, max, and average of the balances. I have done this before using for loops, but never with a while loop. Is there a way to pull the min max and average straight from the array without interfering with the while loop perhaps?
10
Helene 1000
Jordan 755
Eve 2500
Ken 80
Andrew 999
David 1743
Amy 12
Sean 98
Patrick 7
Joy 14
where 10 is the number of accounts
import java.util.*;
import java.io.*;
import java.util.Arrays;
public class bankaccountmain {
public static void main(String[] args) throws FileNotFoundException {
Scanner inFile = null;
try {
inFile = new Scanner(new File("account.txt"));
;
} catch (FileNotFoundException e) {
System.out.println("File not found!");
System.exit(0);
}
int count = 0;
int accounts = inFile.nextInt();
String[] names = new String[accounts];
int[] balance = new int[accounts];
while (inFile.hasNextInt()) {
inFile.next();
names[count] = inFile.next();
inFile.nextInt();
balance[count] = inFile.nextInt();
count++;
}
System.out.println(Arrays.toString(names));
System.out.println(Arrays.toString(balance));
}
}