I can't save var stop so it can stop for cycle. I just need when tryOpen is true to exit that method and stop doing recursion.
public void moznosti(char [] arr, String pr, int a, int b) {
boolean stop = false;
if (b == 0) {
char [] heslo = pr.toCharArray();
for (int i = 0; i < heslo.length; i++) {
System.out.print(heslo[i]);
}
System.out.println();
if (tryOpen(heslo)) {
stop = true;
System.out.println("END");
}
return;
}
if (stop == false) {
for (int i = 0; i < a; i++) {
String tmp = pr+arr[i];
moznosti(arr, tmp, a, b-1);
}
}
}
Aucun commentaire:
Enregistrer un commentaire