summaryrefslogtreecommitdiffstats
path: root/Java/MinMaxAvg.java
blob: 0580f2181e156c1fe2ac9507a7a427c7ec02c18b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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