import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.File; import java.io.FileReader; import java.io.FileNotFoundException; class MinMaxAvg { public static void main(String[] args) throws java.io.IOException{ int min = 2147483647; //Worst fix I have ever decided to do, but the minimum starts out as the highest number java can read in 32 bits. int max = 0; float avg = 0; int length = 0; String fileloc; try{ //get file location with buffered reader, bad on space, good on time System.out.println("input file location:"); BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); fileloc = input.readLine(); File f=new File(fileloc); FileReader file = new FileReader(f); BufferedReader readfile = new BufferedReader(new FileReader(fileloc)); String line; int currentline; while ((line = readfile.readLine()) != null) { currentline = Integer.parseInt(line); length++; // System.out.println("I am currently reading line " + length + " and it has a value of " + currentline); if (currentline > max){ max = currentline; // System.out.println("Max is currently " + min); } if (currentline < min) { min = currentline; // System.out.println("Minimum is currently " + min); } avg = avg + currentline; // System.out.println("Avg is currently " + avg); // System.out.println("Epoch " + length + " is complete"); } System.out.println("Minimum is: " + min); System.out.println("Maximum is: " + max); System.out.println("Average is: " + (avg/length)); }catch(FileNotFoundException e) { System.out.println("No Inputfile Provided"); } } } //By msglm; Licensed under the AGPL v3