Boyan5

oop3

Jun 24th, 2021
634
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.Scanner;
  2. public class zad3 {
  3.     public static void main(String[] args) {
  4.         Scanner scanner = new Scanner(System.in);
  5.         int i,j;
  6.         int min = 0;
  7.         System.out.print("Enter rows for the array : ");
  8.         int rows = scanner.nextInt();
  9.         System.out.print("Enter columns for the array: ");
  10.         int cols = scanner.nextInt();
  11.         System.out.println("Enter " + (rows * cols) + " array elements: ");
  12.         int matrix[][] = new int[rows][cols];
  13.         int[] minMatrix=new int[cols];
  14.         for ( i = 0; i < rows; i++) {
  15.             for ( j = 0; j < cols; j++) {
  16.                 matrix[i][j] = scanner.nextInt();
  17.             }
  18.         }
  19.         for ( i=0; i<cols; i++) {                    
  20.             min = matrix[0][i];
  21.             for ( j = 0; j < rows; j++)
  22.                 if (matrix[j][i] < min) min = matrix[j][i];
  23.             minMatrix[i] = min;
  24.         }
  25.         for ( i = 0; i < rows; i++) {              
  26.             for ( j = 0; j < cols; j++) {
  27.                 System.out.format("%5d" , matrix[i][j]);
  28.             }
  29.             System.out.println();
  30.         }
  31.         for ( i = 0; i < cols; i++) {                
  32.             System.out.format("%5d" , minMatrix[i]);
  33.         }
  34.             }
  35.  
  36.         }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment