Respuesta :
Answer:
- public class Main {
- public static void main (String [] args) {
- double rainFall [][] = {
- {0.88, 1.11, 2.01, 3.64, 6.44, 5.58, 4.23, 4.34, 4.00, 2.05, 1.48, 0.77},
- {0.76, 0.94, 2.09, 3.29, 4.68, 3.52, 3.52, 4.82, 3.72, 2.21, 1.24, 0.80},
- {0.67, 0.80, 1.75, 2.70, 4.01, 3.88, 3.72, 3.78, 3.55, 1.88, 1.21, 0.61},
- { 0.82, 0.80, 1.99, 3.05, 4.19, 4.44, 3.98, 4.57, 3.43, 2.32, 1.61, 0.75},
- {0.72, 0.90, 1.71, 2.02, 2.33, 2.98, 2.65, 2.99, 2.55, 1.99, 1.05, 0.92}
- };
- int year = 2010;
- System.out.println("Year|\tJan\tFeb\tMar\tApr\tMay\tJun\tJul\tAug\tSep\tOct\tNov\tDec");
- for(int i=0; i < rainFall.length; i++){
- System.out.print(year+ " \t");
- for(int j=0; j < rainFall[i].length; j++){
- System.out.print(rainFall[i][j] + " ");
- }
- System.out.println();
- year++;
- }
- double total[] = new double[5];
- for(int i=0; i < rainFall.length; i++){
- total[i] = 0;
- for(int j=0; j < rainFall[i].length; j++){
- total[i] += rainFall[i][j];
- }
- }
- DecimalFormat df = new DecimalFormat("0.00");
- year = 2010;
- System.out.println("Total rainfall for each year:");
- for(int i=0; i < total.length; i++){
- System.out.println(year + " " + df.format(total[i]));
- year++;
- }
- double avgRain[] = new double[12];
- for(int j=0; j < 12; j++){
- double totalMonthRain = 0;
- for(int i = 0; i < 5; i++){
- totalMonthRain += rainFall[i][j];
- }
- avgRain[j] = totalMonthRain / 5;
- }
- System.out.println("Average rainfall for each month:");
- System.out.println("Jan\t\tFeb\t\tMar\t\tApr\t\tMay\t\tJun\t\tJul\t\tAug\t\tSep\t\tOct\t\tNov\t\tDec");
- for(int i=0; i < avgRain.length; i++){
- System.out.print(df.format(avgRain[i]) + "\t");
- }
- }
- }
Explanation
Note: The first line of import statement is missing as Brainly detect it as invalid text. Please refer to attached file to get the full source codes.
Line 10 - 11
Initialize the rainFall array with the sample data
Line 15 - 20
Use double for loop to traverse each item in the rainFall array to display the rain fall data for 12 month in 5 years.
Line 25 - 40
Calculate the total rain fall for each year and display them using a for loop
Line 42 - 56
Calculate the total monthly rain fall for each year and divide it by 5 to get the average rain fall for every month and display it using a for loop.