I made a recursive method to find the least number of rallies that could be played before one or another team wins with given points team should score to win - k, current points of two teams - x and y.
So it looked like
public static int scores(int k, int x, int y, int rally) {
if (x==k || y==k)
return rally;
else {
rally++;
return Math.min(scores(k, x + 1, y, rally), scores(k, x,y+1,rally));
}
}
When I called this method with custom values in main method
scores(5,0,0,0)
It worked fine. But when I changed IF statement to check that the winner has at least two-point margin
if ((x==k || y==k) && Math.abs(x-y)>=2)
The program showed java.lang.StackOverflowError
I am extremely bad at this, please help me