suggestion for lab2

This commit is contained in:
dymik739 2023-04-06 15:20:29 +03:00
parent 9ece98fece
commit 32545562f8
1 changed files with 9 additions and 2 deletions

View File

@ -3,7 +3,7 @@ public class Lab2 {
final int A = 2; final int A = 2;
final int[][] MATRIX_B = { final int[][] MATRIX_B = {
{1, 202, 1, 1, 202, 3, 1, 202, 3,}, {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,}, {1, 1, 3, 1, 202, 3, 1, 202, 3,},
// {4, 5, 6,}, // {4, 5, 6,},
}; };
@ -99,13 +99,20 @@ public class Lab2 {
int sum = 0; int sum = 0;
for (int j = 0; j < MATRIX_C[0].length; j++) { for (int j = 0; j < MATRIX_C[0].length; j++) {
int tmpSmallest = MATRIX_C[0][j]; int tmpSmallest = MATRIX_C[0][j];
boolean value_repeats = false;
for (int i = 1; i < MATRIX_C.length; i++) { for (int i = 1; i < MATRIX_C.length; i++) {
if (MATRIX_C[i][j] < tmpSmallest) { if (MATRIX_C[i][j] < tmpSmallest) {
tmpSmallest = MATRIX_C[i][j]; tmpSmallest = MATRIX_C[i][j];
value_repeats = false;
} else if (MATRIX_C[i][j] == tmpSmallest) {
value_repeats = true;
} }
} }
if (!value_repeats) {
sum += tmpSmallest; sum += tmpSmallest;
} }
}
return sum; return sum;
} }