I'm very new to Java, and this homework assignment is throwing me. I am supposed to print out a 2D array of high temperatures at 4 different times of the day on every day of the week, then get the time averages, the day averages, and the total average. I've been able to get everything except the total average. I have tried so many different things, and I cannot get it to work. I know I need to create some sort of total_sum variable so I can then divide it and get the total average, but I cannot figure out how. I've been told I need to put it outside of the nested loop, like how I declared sum. I know this is probably a dumb/basic question.
package com.company;
public class Temperatures {
public static void main(String[] args) {
System.out.println("Temperature Calculator");
System.out.println("The data provided are: ");
int[][] temps = new int[4][7];
temps[0][0] = 68;
temps[0][1] = 70;
temps[0][2] = 76;
temps[0][3] = 70;
temps[0][4] = 68;
temps[0][5] = 71;
temps[0][6] = 75;
temps[1][0] = 76;
temps[1][1] = 76;
temps[1][2] = 87;
temps[1][3] = 84;
temps[1][4] = 82;
temps[1][5] = 75;
temps[1][6] = 83;
temps[2][0] = 73;
temps[2][1] = 72;
temps[2][2] = 81;
temps[2][3] = 78;
temps[2][4] = 76;
temps[2][5] = 73;
temps[2][6] = 77;
temps[3][0] = 64;
temps[3][1] = 65;
temps[3][2] = 69;
temps[3][3] = 68;
temps[3][4] = 70;
temps[3][5] = 74;
temps[3][6] = 72;
for (int row = 0; row < 4; row++) {
String[] times = {"7 AM: ", "3 PM: ", "7 PM: ", "3 AM: "};
System.out.print(times[row] + " ");
for (int column = 0; column < 7; column++) {
System.out.print(temps[row][column] + " ");
}
System.out.println();
}
System.out.println(" ");
System.out.println("Based on that data, the following are the average temperatures for the week.");
int sum;
for (int column = 0; column < temps[0].length; column++) {
String[] days = {"Sun: ", "Mon: ", "Tue: ", "Wed: ", "Thu: ", "Fri: ", "Sat: "};
System.out.print(days[column]);
sum = 0;
for (int row = 0; row < temps.length; row++) {
sum += (temps[row][column]);
}
int average = sum / temps.length;
System.out.println(average);
}
System.out.println();
for (int row = 0; row < temps.length; row++) {
String[] times = {"7 AM: ", "3 PM: ", "7 PM: ", "3 AM: "};
System.out.print(times[row]);
sum = 0;
for (int column = 0; column < temps.length; column++) {
sum += (temps[row][column]);
}
int average = sum / temps.length;
System.out.println(average);
}
}
}