1Please define a two dimensional array to hold the following

1.)Please define a two dimensional array to hold the following table

12

14

8

25

107

88

15

17

70

71

18

23

The first dimension holds the rows and the second dimension holds the columns.

For the numbers in each row, please output their maximum, minimum and summary.

For the numbers in each column, please output their maximum, minimum and summary.

For the numbers in the whole table, please output their maximum, minimum and summary.

Please name this codes as Table.java

12

14

8

25

107

88

15

17

70

71

18

23

Solution

Table.java

public class Table {

   public static void main(String[] args) {
       int a[][] = {{12,14,8},{25,107,88},{15,17,70},{71,18,23}};
      
       for(int i=0; i<a.length;i++){
           System.out.println(\"Row \"+(i+1)+\": \");
           int max = a[i][0];
           int min = a[i][0];
           int sum = 0;
           for(int j=0; j<a[i].length; j++){
               if(max < a[i][j]){
                   max = a[i][j];
               }
               if(min > a[i][j]){
                   min = a[i][j];
               }
               sum = sum + a[i][j];
           }
           System.out.println(\"Max: \"+max);
           System.out.println(\"Min: \"+min);
           System.out.println(\"Summary: \"+sum);
           System.out.println();
       }
      
       for(int i=0; i<a[0].length;i++){
           System.out.println(\"Column \"+(i+1)+\": \");
           int max = a[0][i];
           int min = a[0][i];
           int sum = 0;
           for(int j=0; j<a.length; j++){
               if(max < a[j][i]){
                   max = a[j][i];
               }
               if(min > a[j][i]){
                   min = a[j][i];
               }
               sum = sum + a[j][i];
           }
           System.out.println(\"Max: \"+max);
           System.out.println(\"Min: \"+min);
           System.out.println(\"Summary: \"+sum);
           System.out.println();
       }
       int max = a[0][0];
       int min = a[0][0];
       int sum = 0;
       System.out.println(\"Table: \");
       for(int i=0; i<a.length;i++){
           for(int j=0; j<a[i].length; j++){
               if(max < a[i][j]){
                   max = a[i][j];
               }
               if(min > a[i][j]){
                   min = a[i][j];
               }
               sum = sum + a[i][j];
           }
          
       }
       System.out.println(\"Max: \"+max);
       System.out.println(\"Min: \"+min);
       System.out.println(\"Summary: \"+sum);
       System.out.println();
      
   }
}

Output:

Row 1:
Max: 14
Min: 8
Summary: 34

Row 2:
Max: 107
Min: 25
Summary: 220

Row 3:
Max: 70
Min: 15
Summary: 102

Row 4:
Max: 71
Min: 18
Summary: 112

Column 1:
Max: 71
Min: 12
Summary: 123

Column 2:
Max: 107
Min: 14
Summary: 156

Column 3:
Max: 88
Min: 8
Summary: 189

Table:
Max: 107
Min: 8
Summary: 468

1.)Please define a two dimensional array to hold the following table 12 14 8 25 107 88 15 17 70 71 18 23 The first dimension holds the rows and the second dimen
1.)Please define a two dimensional array to hold the following table 12 14 8 25 107 88 15 17 70 71 18 23 The first dimension holds the rows and the second dimen
1.)Please define a two dimensional array to hold the following table 12 14 8 25 107 88 15 17 70 71 18 23 The first dimension holds the rows and the second dimen

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site