I am using recursion inside a loop. I want to stop the loop as soon as the method is called recursively and resume it again when the call returns. I am not able to do so. Do I need to lock the method?
Here is my code:
import java.lang.Thread;
public class Max2Friends extends Thread {
String[] f = {"NYNNN", "YNYNN", "NYNYN", "NNYNY", "NNNYN"};
int[] twof = {0, 0, 0, 0, 0};
public static void main(String[] args) {
Max2Friends obj=new Max2Friends();
obj.Calculate(999,999);
}
public void Calculate(int p, int t) {
System.out.println("p=" + p);
System.out.println("t=" + t);
for (int i = 0; i != p && i < 5; i++) {
System.out.println("i=" + i);
System.out.println("p value inside=" + p);
System.out.println("t value inside=" + t);
if (i == t)
i=i+1;
for (int j = 0; j < 5; j++) {
if (f[i].charAt(j) == 'Y' && p == 999) {
Calculate(i,j);
} else if (f[i].charAt(j) == 'Y' && j == t) {
twof[p]++;
break;
}
}
}
}
}