I am working on a coding project where I have to have a user input five specific float values. Then based on those values I have to to get a total, maximum, minimum and then apply interest. I am stuck right now on getting the minimum value from the array. I have been able to get the maximum value but when I print the minimum value I get 0.0. Any ideas?
import java.util.Scanner;
public class float_assignment {
public static void main(String[] args) {
float[] userNum = new float[5];
float total = 0;
float average = 0;
float maximum = userNum[0];
float minimum = userNum[0];
float interest = 0;
int i = 0;
Scanner scnr= new Scanner(System.in);
for (i = 0; i <= 4; ++i) {
System.out.println("Please enter a number with a single decimal value:");
userNum[i] = scnr.nextFloat();
}
for (i = 0; i < userNum.length; ++i) {
if (userNum[i] > maximum) {
maximum = userNum[i];
}
}
for (i = 0; i < userNum.length; ++i) {
if(userNum[i] < minimum) {
minimum = userNum[i];
}
}
total = userNum[0] + userNum[1] + userNum[2] + userNum [3] + userNum [4];
System.out.println("");
System.out.println("Total value is: " + total);
System.out.println("");
System.out.println("Maximum Vaule is: " + maximum);
System.out.println("");
System.out.println("Minimum Vaule is: " + minimum);
}
}