Advertisement
Vankata17

FuntionsWithMatrix

Mar 15th, 2021
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. package Second.Semester;
  2.  
  3. public class functionsOfMatrix {
  4.     public static void main(String[] args) {
  5.         int[][] numbers = {
  6.                 {2, 5, 7, 8},
  7.                 {1, 3, 4, 9}
  8.         };
  9.         int min = Integer.MAX_VALUE;
  10.         int max = 0;
  11.         double sum = 0;
  12.         double avg = 0;
  13.         for (int row = 0; row < numbers.length; row++) {
  14.             int[] currentRow = numbers[row];
  15.             for (int cols = 0; cols < currentRow.length; cols++) {
  16.  
  17.                 if (currentRow[cols] > max) {
  18.                     max = currentRow[cols];
  19.                 }
  20.                 if (currentRow[cols] < min) {
  21.                     min = currentRow[cols];
  22.                 }
  23.  
  24.  
  25.                 sum += currentRow[cols];
  26.  
  27.             }
  28.             avg = sum / currentRow.length;
  29.             System.out.println("The min of " + row + " row is: " + min);
  30.             System.out.println("The max of " + row + " row is: " + max);
  31.             System.out.printf("The sum of " + row + " row is: %.0f ", sum);
  32.             System.out.println();
  33.             System.out.print("The average is: ");
  34.             System.out.printf("%.2f", avg);
  35.             System.out.println();
  36.             sum = 0;
  37.  
  38.         }
  39.  
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement