From 399941844fbcd9ca16ef312e913fa09daca54ab0 Mon Sep 17 00:00:00 2001 From: Oleksii Aleshchenko Date: Thu, 30 Mar 2023 15:50:18 +0300 Subject: [PATCH] update lab2 --- src/Lab2.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Lab2.java b/src/Lab2.java index 4089632..56489af 100644 --- a/src/Lab2.java +++ b/src/Lab2.java @@ -2,17 +2,17 @@ public class Lab2 { public static void main(String[] args) { final int A = 2; final int[][] MATRIX_B = { - {1, 202, 3,1, 202, 3,1, 202, 3,}, - {202, 3,1, 202, 3,1, 202, 3,}, - {3,1, 202, 3,1, 202, 3,}, - {4, 5, 6,}, + {1, 202, 1, 1, 202, 3, 1, 202, 3,}, + {1, 202, 1, 1, 202, 3, 1, 202, 3,}, + {1, 1, 3, 1, 202, 3, 1, 202, 3,}, +// {4, 5, 6,}, }; int[][] MATRIX_C = multiplication(A, MATRIX_B); print(MATRIX_C); - System.out.println("Sum of smallest elements in every column:" + sumOfSmallestElementsInEveryColumn(MATRIX_C)); + System.out.println("Sum of smallest elements in every column: " + sumOfSmallestElementsInEveryColumn(MATRIX_C)); /*int[] array = {1, 2, 3}; int[] array2 = new int[3]; @@ -63,11 +63,13 @@ public class Lab2 { private static int sumOfSmallestElementsInEveryColumn(final int[][] MATRIX_C) { // todo check different length of rows +// todo try to change i and j +// todo check repetition of minimal elements int sum = 0; for (int i = 0; i < MATRIX_C[0].length; i++) { int tmpSmallest = MATRIX_C[0][i]; for (int j = 1; j < MATRIX_C.length; j++) { - if (tmpSmallest < MATRIX_C[j][i]) { + if (MATRIX_C[j][i] < tmpSmallest) { tmpSmallest = MATRIX_C[j][i]; } }