9. write a program to solve this problem. The weather station records the outsid
ID: 3698242 • Letter: 9
Question
9. write a program to solve this problem. The weather station records the outside temperature even hour for 24 hours. It then needs to calculate the minimum and the average temperatures for the day. Write a program that will read 24 temperature values(type double) and produce the required output. You may use an array, but you do not hav to. A few lines of code are given. What you add must be consistent with what is given. You must declare any other variables you need Prompting for input is not necessary?
is for java programming
Explanation / Answer
Program:
import java.util.Scanner;
public class Temperature {
public static void main(String str[]){
double avg=0,min;
Scanner sca=new Scanner(System.in);
System.out.println("Enter temperature of 24 hour ");
double []temp=new double[24];
for(int i=0;i<24;i++){
temp[i]=sca.nextDouble();
avg=avg+temp[i];
}
min=temp[0];
avg=avg/24;
for(int i=1;i<24;i++){
if(min>temp[i]){
min=temp[i];
}
}
System.out.println("Average Temprature : "+avg);
System.out.println("Minimum Temprature : "+min);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.