Boyan5

oop2

Jun 24th, 2021
861
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class zad2 {
  3.     public static void main(String[] args) {
  4.         Scanner scanner = new Scanner(System.in);
  5.         int i, j;
  6.         int times = 0;
  7.         double sum = 0;
  8.         System.out.print("Enter rows for the array : ");
  9.         int rows = scanner.nextInt();
  10.         System.out.print("Enter columns for the array: ");
  11.         int cols = scanner.nextInt();
  12.         System.out.println("Enter " + (rows * cols) + " array elements: ");
  13.         int[][] matrix = new int[rows][cols];
  14.         for (i = 0; i < rows; i++) {
  15.             for (j = 0; j < cols; j++) {
  16.                 matrix[i][j] = scanner.nextInt();
  17.             }
  18.         }
  19.  
  20.         for (i = 0; i < rows; i++) {
  21.             sum = 0;
  22.             for (j = 0; j < cols; j++) {
  23.                 System.out.format("%10d", matrix[i][j]);
  24.                 sum += matrix[i][j];
  25.             }
  26.             System.out.format("%10.2f\n", sum / cols);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment