Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws IOException {
- int[] arr = new int[6];
- BufferedReader reader = null;
- int counter = 0;
- try {
- reader = new BufferedReader(new FileReader("C:\\Users\\gzero\\OneDrive\\Desktop\\lab stuff.txt"));
- String text = null;
- while ((text = reader.readLine()) !=null)
- {
- arr[counter]=Integer.parseInt(text);
- counter++;
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- System.out.println("lab stuff.txt doesn't exist");
- } catch (IOException e) {
- e.printStackTrace();
- }
- sort(arr);
- System.out.println(Arrays.toString(arr));
- File output = new File("LabFinal.txt");
- output.createNewFile();
- FileWriter writer = new FileWriter(output);
- writer.write(Arrays.toString(arr)+ "\n Average rainfall is " +
- average(arr)+ "\n The minimum is "+minimum(arr));
- reader.close();
- writer.close();
- }
- public static void sort(int a[])
- {
- int n = a.length;
- for(int i = 0; i< n-1; i++)
- {
- int minIDX = i;
- for(int j = i+1; j<n; j++)
- {
- if(a[j]> a[minIDX])
- minIDX=j;
- }
- int temp = a[minIDX];
- a[minIDX]=a[i];
- a[i]= temp;
- }
- }
- public static int average(int a[])
- {
- int total=0;
- for(int i =0; i>a.length;i++)
- {
- total = a[i]+total;
- }
- return total/6;
- }
- public static int minimum(int a[])
- {
- int min= a[0];
- for(int i= 0; i>a.length;i++)
- {
- if(min >a[i])
- {
- min = a[i];
- }
- }
- return min;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement