Knowee
Questions
Features
Study Tools

Assume that there are 15 locations and assume that you have generated 365 random numbers for temperature values for each location.These values are stored in a 2-D array. Write a Java program to calculate the average annual temperature for each location.     Hint : generate random values between ‐10°c and 35°c using Math.random() method

Question

Assume that there are 15 locations and assume that you have generated 365 random numbers for temperature values for each location.These values are stored in a 2-D array. Write a Java program to calculate the average annual temperature for each location.     Hint : generate random values between ‐10°c and 35°c using Math.random() method

🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple Java program that generates random temperature values for 15 locations over 365 days and calculates the average annual temperature for each location:

public class Main {
    public static void main(String[] args) {
        double[][] temperatures = new double[15][365];
        double[] averageTemperatures = new double[15];

        // Generate random temperatures for each location
        for (int i = 0; i < 15; i++) {
            for (int j = 0; j < 365; j++) {
                temperatures[i][j] = -10 + (Math.random() * ((35 - (-10)) + 1));
            }
        }

        // Calculate the average temperature for each location
        for (int i = 0; i < 15; i++) {
            double sum = 0;
            for (int j = 0; j < 365; j++) {
                sum += temperatures[i][j];
            }
            averageTemperatures[i] = sum / 365;
            System.out.println("Average annual temperature for location " + (i+1) + " is " + averageTemperatures[i]);
        }
    }
}

This program first generates the random temperatures for each day at each location. It then calculates the average temperature for each location by summing all the temperatures for that location and dividing by the number of days (365). The average temperatures are then printed out.

This problem has been solved

Similar Questions

Create an array to store temperatures. Read N temperatures recorded in a day. Create another array to represent the updated temperatures. Copy the elements of the temperature array into the updated temperature array and increment the elements of the temperature array by a value of 10 if the temperature is >30.Print the  updated temperature.Print the  temperature.Sample Input4 (Read N -Total number of temperatures recorded)30 323723Sample Output30 42 47 2330 32 37 23

Daily Temperature AnalysisYou are a meteorologist who needs to analyze temperature data for the last 10 days. Write a program that reads the temperatures into an array and finds the average temperature over these 10 days.Constraints:NAExample:Sample Input:30323129283335343231Sample Output:31.5Explanation:The average temperature over 10 days is 31.5

The list below includes the temperature for 13 days. Let the user to input one number and add it in the beginning of the list. write code to print any value in the list that is greater than 40.Use the following list[35, 33, 37, 40, 41, 44, 40, 39, 45, 38, 40, 42, 47]

The average temperature of a city in the first four days of a month was 36°.The average for the 2nd, 3rd, 4th and 5th day was 38°.If the temperature of the 1st and 5th day were in the ratio 4 : 5, then what is the temperature on the fifth day ?32°35°38°40

The average temperature of a city in the first four days of a month was 36°.The average for the 2nd, 3rd, 4th and 5th day was 38°.If the temperature of the 1st and 5th day were in the ratio 4 : 5, then what is the temperature on the fifth day ?

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.