summaryrefslogtreecommitdiffstats
path: root/Java/MinMaxAvg.java
diff options
context:
space:
mode:
authormsglm <msglm@techchud.xyz>2023-01-14 05:31:48 -0600
committermsglm <msglm@techchud.xyz>2023-01-14 05:31:48 -0600
commit9d53d8857eaa1c9405894a88ca75bc4657e42f35 (patch)
treeeb1efc1d028b949dd83bb710c68be8eff58f26e7 /Java/MinMaxAvg.java
downloadschool-code-master.tar.gz
school-code-master.tar.bz2
school-code-master.zip
Inital CommitHEADmaster
Diffstat (limited to 'Java/MinMaxAvg.java')
-rw-r--r--Java/MinMaxAvg.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/Java/MinMaxAvg.java b/Java/MinMaxAvg.java
new file mode 100644
index 0000000..0580f21
--- /dev/null
+++ b/Java/MinMaxAvg.java
@@ -0,0 +1,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