I'm doing an exercise in Java to check if a vector is inside a matrix. In case the first position of the vector coincides with the current position of the matrix, I will jump to the next position of the vector to follow the check. My problem comes when I jump the row in the matrix and set the position of the vector to 0. I do not know how to establish this condition.
public static PosicionMatriz buscaVectorEnMatriz(int[][] matriz, int[] vector) {
int coincidencia = 0;
int avance = 0;
PosicionMatriz pm;
int columna = 0;
int fila = 0;
vector = new int[3];
vector[0] = 3;
vector[1] = 5;
vector[2] = 6;
matriz = new int[3][3];
matriz[0][0] = 1;
matriz[0][1] = 5;
matriz[0][2] = 3;
matriz[1][0] = 3;
matriz[1][1] = 5;
matriz[1][2] = 6;
matriz[2][0] = 2;
matriz[2][1] = 9;
matriz[2][2] = 0;
for (int i = 0; i < matriz.length; i++) { // recorre el eje de la y
for (int j = 0; j < matriz[0].length; j++) {// recorre el eje de la x
for (int k = 0; k < vector.length; k++) { // recorre el vector
if (vector.length > matriz[i].length) { // Si longitud de vector > que longitud de la fila pasa a la siguiente
coincidencia = 0;
i++; // Saltamos de fila
}
if (vector[k] == matriz[i][j]) {
coincidencia++;
System.out.println("Se ha encontrado la coincidencia en " + "[" + (i) + "]" + "[" + (j) + "]");
} else {
k = 0; // Reestablecemos la posición del vector a la primera si no coincide con la de la matriz
coincidencia = 0;
}
if(coincidencia == vector.length) {
System.out.println("Finaliza la búsqueda");
}
}
}
}
return null;
}