Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class zad3 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int i,j;
- int min = 0;
- System.out.print("Enter rows for the array : ");
- int rows = scanner.nextInt();
- System.out.print("Enter columns for the array: ");
- int cols = scanner.nextInt();
- System.out.println("Enter " + (rows * cols) + " array elements: ");
- int matrix[][] = new int[rows][cols];
- int[] minMatrix=new int[cols];
- for ( i = 0; i < rows; i++) {
- for ( j = 0; j < cols; j++) {
- matrix[i][j] = scanner.nextInt();
- }
- }
- for ( i=0; i<cols; i++) {
- min = matrix[0][i];
- for ( j = 0; j < rows; j++)
- if (matrix[j][i] < min) min = matrix[j][i];
- minMatrix[i] = min;
- }
- for ( i = 0; i < rows; i++) {
- for ( j = 0; j < cols; j++) {
- System.out.format("%5d" , matrix[i][j]);
- }
- System.out.println();
- }
- for ( i = 0; i < cols; i++) {
- System.out.format("%5d" , minMatrix[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment