From 32545562f8956481c74f43abfe343cf2efdaecf2 Mon Sep 17 00:00:00 2001 From: dymik739 Date: Thu, 6 Apr 2023 15:20:29 +0300 Subject: [PATCH] suggestion for lab2 --- src/Lab2.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Lab2.java b/src/Lab2.java index f209094..5302f88 100644 --- a/src/Lab2.java +++ b/src/Lab2.java @@ -3,7 +3,7 @@ public class Lab2 { final int A = 2; final int[][] MATRIX_B = { {1, 202, 1, 1, 202, 3, 1, 202, 3,}, - {1, 202, 1, 1, 202, 3, 1, 202, 3, 4}, + {1, 202, 1, 1, 202, 3, 1, 202, 3,}, {1, 1, 3, 1, 202, 3, 1, 202, 3,}, // {4, 5, 6,}, }; @@ -99,12 +99,19 @@ public class Lab2 { int sum = 0; for (int j = 0; j < MATRIX_C[0].length; j++) { int tmpSmallest = MATRIX_C[0][j]; + boolean value_repeats = false; for (int i = 1; i < MATRIX_C.length; i++) { if (MATRIX_C[i][j] < tmpSmallest) { tmpSmallest = MATRIX_C[i][j]; + value_repeats = false; + } else if (MATRIX_C[i][j] == tmpSmallest) { + value_repeats = true; } } - sum += tmpSmallest; + + if (!value_repeats) { + sum += tmpSmallest; + } } return sum; }