Q:

Write a java program that reads 7 temperatures from the user and shows which are above and which are below the average of the 7 temperatures

0

Write a java program that reads 7 temperatures from the user and shows which are above and which are below the average of the 7 temperatures.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	/* define and create double array a of size 7*/
double ar[]=new double[7];	
//Read temperatures and compute their average
System.out.println("enter 7 tempretures:");
Scanner input=new Scanner(System.in);
double totalTempretures=0;
for(int i=0;i<7;i++)
{
ar[i]=input.nextDouble();
totalTempretures=totalTempretures+ar[i];
}
//compute their average
double average=totalTempretures/7;
System.out.println("the average tempreture is "+average);

   //Display each temperature and its relation to the average
   for(int i=0;i<7;i++)
   {
       System.out.print(ar[i]);
   if (ar[i]>=average) 
   {
       System.out.println(" above average");
   }
   else {System.out.println(" below average");}
	}
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now