I'm trying to solve this exercise to see if you can help me ...
Encode a Java program that reads the temperatures for the month of January and calculate and display:
- Average temperature
- The lowest temperature
- How many days have had temperatures above the average
My problem is as follows. When I try to get the lowest temperature, I always get 0 and I do not know why. I should get the lowest value. Thanks for the help in advance ...
public class ejercicio {
static Scanner leer = new Scanner(System.in);
public static void main(String[] args) {
int cont=0;
double mediaTemperatura = 0;
int Array[] = new int[5];
int baja = Array[0];
for (int i = 0; i < Array.length; i++) {
int dia=i;
System.out.println("Dime la temperatura del dia " + dia);
Array[i] = leer.nextInt();
mediaTemperatura += Array[i];
if (Array[i] < baja) {
baja = Array[i];
}
}
mediaTemperatura = mediaTemperatura / Array.length;
for (int i = 0; i < Array.length; i++) {
if (Array[i]>mediaTemperatura){
cont++;
}
}
System.out.println("La temperatura media es " + mediaTemperatura);
System.out.println("La temperatura mas baja es:" +baja);
System.out.println("Hay " + cont + " dias con temperatura mayor a la media");
}
}