I'm trying to get the minimum and maximum values from an array of doubles. The maximum value works fine, however, the minimum value always seems to be zero. What would be the best way to get the minimum value? Please note that I cannot use a for loop in this exercise, but a while loop.
public class LoopingFloats {
public static void main(String[] args) {
double[] inputHolder = new double[5];
int inputCounter = 0;
double total = 0.0d;
double average = 0.0d;
double maximum = 0.0d;
double minimum = inputHolder[inputCounter];
double interestRate = 0.20d;
double interestAmount = 0.0d;
Scanner scnr = new Scanner(System.in);
while(inputCounter <= 4){
System.out.println("Enter number " + (inputCounter + 1) + ": ");
inputHolder[inputCounter] = scnr.nextDouble();
if(inputHolder[inputCounter] > maximum){
maximum = inputHolder[inputCounter];
}
if(inputHolder[inputCounter] < minimum){
minimum = inputHolder[inputCounter];
}
total = total + inputHolder[inputCounter];
inputCounter += 1;
}
}
average = total / 5;
interestAmount = total * interestRate;
System.out.println("Total: " + total);
System.out.println("Average: " + average);
System.out.println("Maximum: " + maximum);
System.out.println("Minimum: " + minimum);
System.out.println("Interest for total at 20%: " + interestAmount);
}
}
double[]array.