I have the following code but I need to pass it recursively:
public static void agregarAuxiliarPalabras(String matriz[][], ArrayList<String> al, int a, int b) {
String aux = "";
// if(a>matriz.length){
// return matriz;
// }
while (a < matriz.length) {
aux = matriz[a][b];
JOptionPane.showMessageDialog(null, "Palabra:" + aux);
if (b == matriz[0].length - 1) {
a++;
b = 0;
} else {
b++;
}
}
}
I tried to do it and this was the result:
public static ArrayList<String> agregarAuxiliarPalabras_Recursivo(String matriz[][], ArrayList<String> al, int a, int b) {
String aux = "";
if (a <= matriz.length) {
if (b > matriz[0].length - 1) {
// System.out.println(j);
b = 0;
return agregarAuxiliarPalabras_Recursivo(matriz, al, a++, b);
} else {
aux = matriz[a][b];
JOptionPane.showMessageDialog(null, "Palabra:" + aux);
return agregarAuxiliarPalabras_Recursivo(matriz, al, a, b++);
}
}
return al;
}
The problem is that when running it, there is clearly a problem and it only prints the first word entered, maybe it will be an error in some condition or IF-ELSE instruction? Thanks...
Try this: