Please write the code in JAVA! Here is a definition of integer array for 7 tempe
ID: 3813156 • Letter: P
Question
Please write the code in JAVA!
Here is a definition of integer array for 7 temperatures of the week. It is already initialized and there are variables declared for the minimum, maximum, total and average temperatures. These variables are going to be used to get the these values for this weekly temperature. int weekly Temp [] = {69, 70, 71, 68, 66, 71, 70}; int i max = 0, min = 0; float total = 0, average; Given the above definition, write the code to: a) Print the daily temperature (assume, first day Sunday), e.g. The temperature on day 1 was 69: b) Find and print the minimum and maximum temperature of the week c) Calculate and print the average temperature of the week Sample output: The temperature on day 1 was 69: The temperature on day 2 was 70: The temperature on day 3 was 71: The temperature on day 4 was 68: The temperature on day 5 was 66: The temperature on day 6 was 71: The temperature on day 7 was 70: The Minimum temperature is: 66: The Maximum temperature is: 71 The average temperature for the week is: 69.28571 Thank you for using my homework #5 solutionExplanation / Answer
program :
public class Temp {
public static void main(String[] args)
{
int WeeklyTemp[]= {69,70,71,68,66,71,70};
int i,max= 0,min=0;
float total =0,average;
for(i = 0; i < 7 ; i++)
{
System.out.println("the temperature on day "+(i+1)+" was "+WeeklyTemp[i]);
}
for(i = 0; i < 7 ; i++)
{
total = total+ WeeklyTemp[i];
}
min = WeeklyTemp[0];
max = WeeklyTemp[0];
for(i=1; i<7; i++)
{
if(WeeklyTemp[i] > max)
max = WeeklyTemp[i];
else if (WeeklyTemp[i] < min)
min= WeeklyTemp[i];
}
average = total / 7;
System.out.println("maximum temperature of this week is :"+max);
System.out.println("minimum temperature of this week is :"+min);
System.out.println("Average temperature of this week is :"+average);
}
}