/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArraysAndMethodsGames.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package com.calebfontenot.lab16_arrays2_calebfontenot;
import java.util.Scanner;
@author
public class ArraysAndMethodsGames {
public static double min(double[] array) {
double lowest = array[0];
for (int i = 1; i < (array.length -1); i++) {
lowest = Math.min(lowest, array[i]);
}
return lowest;
}
public static double[] readArray() {
int doublesRemaining = 10;
double[] returnArray = new double[doublesRemaining];
Scanner input = new Scanner(System.in);
int i = 0;
do {
System.out.print("Enter 10 doubles (" + doublesRemaining + " left ): ");
returnArray[i] = input.nextDouble();
i++;
doublesRemaining--;
} while (doublesRemaining != 0);
return returnArray;
}
@param array
@return
public static double average(double[] array) {
double returnDouble = 0.0;
for (double i: array) {
returnDouble += i;
}
returnDouble /= (double) array.length;
return returnDouble;
}
public static void main(String[] args)
{
double[] doubleArray = new double[10];
doubleArray = readArray();
System.out.println("average function returns: " + average(doubleArray));
System.out.println("lowest function returns: " + min(doubleArray));
}
}