IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest temperatures...

Free

80.2K

Verified Solution

Question

Programming

IN JAVA

Write a program that uses a two-dimensional array to store thehighest and lowest temperatures for each month of the year. Promptthe user for 12 months of highest and lowest.  Write two methods : one to calculate and returnthe average high and one to calculate and return the average low ofthe year. Your program should output all the values in the arrayand then output the average high and the average low.

im trying to figure out how to get a 2D array to store a numberfor the highest and the lowest of each month. I can get it to doeither the highest or lowest but not both.

Thanks

Answer & Explanation Solved by verified expert
4.5 Ratings (721 Votes)

import java.util.Scanner;
class ArrayAssignmentClient {

public static void main(String[]args){


int i,j;
double [][] arr = new double[12][2];
Scanner scan = new Scanner(System.in);

System.out.print(\"Enter lowest and highest temparatures of 12 months : \");
for(i=0; i<12; i++)
{
for(j=0; j<2; j++)
{
arr[i][j] = scan.nextDouble();
}
}


System.out.print(\"The lowest and highest temparatures of 12months are :\n\");
for(i=0; i<12; i++)
{
for(j=0; j<2; j++)
{
System.out.print(arr[i][j]+ \" \");
}
System.out.println();
}
System.out.println(averageHigh(arr));
System.out.println(averageLow(arr));


}


public static double averageHigh(double[][]arr){
double total = 0;
double average = 0;
for (int i = 0; i <12; i++) {
total += arr[i][1];
average = total /12;
}
return average;
}

public static double averageLow(double[][]arr){
double total = 0;
double average = 0;
for (int i = 0; i <12; i++) {

total += arr[i][0];
average = total / 12;
}
return average;

}
}


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students