Hello, I have the following question/doubt...
what this code does is given an array multiply its elements by an integer and return it
static int[] multiplicarArray(int[] arr, int k) {
int[] nuevo = new int[arr.length];
for(int i = 0;i < arr.length; i++) {
nuevo[i] = arr[i] * k;
}
return nuevo;
}
what I would like is that, given a matrix, check if one of its columns is the multiplied array, but it would not be working for me (I know that the code below is wrong but it would not be finding the solution)
static boolean existeColumnaMultiplol(int[][] mat, int[] vec, int k) {
boolean res = false;
int[] nuevo = multiplicarArray(vec, k);
for (int i = 0; i < vec.length; i++) {
for (int c = 0; c < mat[0].length; c++) {
for (int f = 0; f < mat.length; f++)
res = res || (mat[f][c] == nuevo[i]);
}
}
return res;
}
Well let's see what you think, I did it with the following method, it compares the numbers from the first column to the bottom and then the second and so on...
And the complete code would be something like this
The counter variable increases as it matches the new array, at the end a comparison is made, if the counter is equal to array.length, which means that all the numbers in that column match those of the multiplied array ( if they have the same capacity, array.length and new.length)