I am trying the following: To go through all the positions (not elements) of a matrix. The normal way to traverse a matrix is usually done with two for, but in this case I want to get the two, that is. In the position matrix
00 01 02 03
10 11 12 13
20 21 22 23
A for that generates the position 00 and then another that generates the positions of the rest of the matrix. 01, 02, 03, 10, 11, 12, 13, 20, 21, 22, 23 From there, it would pass to position 01, in which it compares with 00, 02, 03, 10, 11, 12, 13, 20, 21, 22, 23. I do not know if linking 4 loops of type for is the most direct way, because I think it would overload the method a bit. Or it is necessary recursion, but it is usually not recommended but sometimes the most direct solution. Can anyone tell me which is the most correct solution?
I have a method that if it finds elements repeated 3 times or more per column, coviente those elements to 0. The user exchanges the positions of the matrix, to form that block of 3 or more. So what I want is a method that before the user enters the entry to exchange the elements, check if he can do the movement. Therefore, by checking all the possible entries that the user enters, I can determine if there is or there is not. The user can only make movements and swap up, down, right or left. The exchange method already I have it done
For position 12 the user could only enter 02 22 11 13 what would be when they would be exchanged. Then check if it makes the block. If you do not block, it returns the array as it was. Only the positions below are suitable for the center.
02
11 12 13
22
Summary The code I have (I do not do well all with all)
public static void genera(int[][] matriz) {
boolean hay = true;
for (int fil = 0; fil < lado; fil++) {
for (int col = 0; col < lado; col++) {
for (int fil1 = 0; fil < ladoh; fil1++) {
for (int col1 = 0; col1 < ladoh; col1++) {
if (contiguo(fil, col, fil1, col1) == true) {
bloque(matriz, lado);
hay = hayCeros(matriz);
System.out.println(hay);
}
}
}
}
}
}
block methods, check if there are 3 or more. There are zeros, see if the block method has converted to zeros (because of the circumstances).