Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using an array and loops, write a program that will ask the user to enter a temp

ID: 3546849 • Letter: U

Question

Using an array and loops, write a program that will ask the user to enter a temperature for each day of the week and will find and print the average temperature, the low temperature, and the high temperature.


Please please help!

*This is a first year beginner java programming class (use putty) please keep it as basic and simple as possible. MUST use array and loops.


So far I have:


import java.util.*;


public class Lab9

{

public static void main(String[]args)

{

Scanner input=new Scanner(System.in);

//input temperature in a week

double[] week=new double[7];


for (int m=0;m<7;m++)

{

System.out.print("Day: "+m+1);

temp[m]=input.nextDouble();

}


//check height and lowest temperature

double high=0.0;

double low=10000.0;


for (int m=0; m<7; m++)

{

if (high<temp[m]){

high=temp[m];

}

if (low>temp[m])

{

low=temp[m];

}

Explanation / Answer

package mypro;

import java.util.*;
public class Lab9 {

public static void main(String[] args) {
Scanner input=new Scanner(System.in);
//input temperature in a week
double[] temp=new double[7];
for (int m=0;m<7;m++){
System.out.print("Day : "+(m+1)+"=");
temp[m]=input.nextDouble();
}
//check height and lowest temperature
double high=temp[0];
double low=temp[0];
double avg=0.0;
for (int m=0; m<7; m++){
avg=avg+temp[m];
if (high>temp[m]){
high=temp[m];
}
if (low<temp[m])
{
low=temp[m];
}
//end of loop

}
System.out.println("The average temperature is="+String.format( "%.2f", avg/7 ));
System.out.println("The highest temperature is= "+high);
System.out.println("The lowest temperature is "+low);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote