Question: The code is not outputing the lowest temperture and ive tried to fix the issue with no luck. any help would be appreciated. import java.util.Scanner;

The code is not outputing the lowest temperture and ive tried to fix the issue with no luck. any help would be appreciated.
import java.util.Scanner;
// craeting TemperatureAnalysis class
public class TemperatureAnalysis {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
// declaring temperature array and variables
float[] temperatures = new float[7];
int aboveFreezing =0;
int belowFreezing =0;
float highestTemperature =0;
float lowestTemperature =0;
float sum =0;
// loop for calculations
for (int i =0; i <7; i++){
System.out.print("Enter temperatures #"+(i+1)+" :");
temperatures[i]= input.nextFloat();
sum += temperatures[i];
if (temperatures[i]>=32){
aboveFreezing++;
} else {
belowFreezing++;
}
if (temperatures[i]> highestTemperature){
highestTemperature = temperatures[i];
}
if (temperatures[i]< lowestTemperature){
lowestTemperature = temperatures[i];
}
}
// ggetting avaerage
float averageTemperature = sum /7;
// print the result
System.out.println("Number of temperatures at or above freezing: "+ aboveFreezing);
System.out.println("Number of temperatures below freezing: "+ belowFreezing);
System.out.println("Highest temperature entered: "+ highestTemperature);
System.out.println("Lowest temperature entered: "+ lowestTemperature);
System.out.println("Average temperature: "+ averageTemperature);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!