I'm trying to create code that calculates the percentage of values between a min and max value (inclusive). The output for this code should be 50.0, but I'm getting 100.0. Any ideas on why this is happening? Thanks! Edit: The code compiles, and I'm not having issues with division. I'm confused as to why the numbers are different. Thanks!
public class Test {
public static double tempCheck(double[][] temps, double minTemp, double maxTemp) {
int i;
int betweenTemps = 0;
double percentage = 0.0;
int j;
int numVals = 0;
for (i = 0; i < temps.length; i++) {
for (j = 0; j < temps[i].length; j++) {
if (temps[i][j] >= minTemp && temps[i][j] <= maxTemp) {
betweenTemps++;
}
}
numVals++;
}
percentage = (betweenTemps / numVals) * 100;
return percentage;
}
public static void main(String[] args) {
double[][] temps = {
{ 72.0, 78.0, 74.5 },
{ 79.0, 80.0, 71.0 }
};
double minTemp = 70.0;
double maxTemp = 75.0;
System.out.println(tempCheck(temps, minTemp, maxTemp));
}
}