Advertisement
TsetsoP

dvumeren masiv

Mar 26th, 2021
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. import java.util.*;
  2. public class DvumerenMasiv {
  3.     public static void main(String[] args) {
  4.  
  5.         Scanner scan = new Scanner(System.in);
  6.         int [][]arr = {
  7.                 {5, 6, 7},
  8.                 {12, 8, 2},
  9.                 {3, 9, 11}
  10.         };
  11.         for (int r = 0; r < arr.length ; r++) {
  12.             int[] currnetRow = arr[r];
  13.             int sum = 0;
  14.  
  15.             int min = (Integer.MAX_VALUE);
  16.             int max = (Integer.MIN_VALUE);
  17.  
  18.             for (int c = 0; c < currnetRow.length ; c++) {
  19.                 int currentElementOnRow = currnetRow[c];
  20.  
  21.                 if(min > currentElementOnRow){
  22.                     min = currentElementOnRow;
  23.  
  24.                 }
  25.                 if(max < currentElementOnRow){
  26.                     max = currentElementOnRow;
  27.  
  28.                 }
  29.                 sum += currentElementOnRow;
  30.             }
  31.             double avg = (double) sum / (double) currnetRow.length;
  32.             String formatAvg = String.format("%.2f", avg);
  33.             System.out.println(" index: " + r +" Sum: " + sum + " Min: " + min  + " Max: " + max + " Avg: " + formatAvg);
  34.             System.out.printf("index: %d Sum: %d Min: %d Max: %d Average %.2f",r,sum,min,max,avg);
  35.             System.out.println();
  36.  
  37.         }
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement