My attempt to write a recursive method to produce the results of the number of combination where x=13 and y=52 and Combination (y, x) =.....
When I use small numbers (e.g.: 2,4) I tend to get a result only when I blank out the 3rd if statement. The formula used below was provided. I also get OverFlowStack error. The code below maybe be weak and I seek help to fix.
public class BridgeGame {
// Need to solve for x=13 and y=52
static long x;
static long y;
public long Combinations(long x, long y) {
// The base case
if (x == 1)
return y;
if (x == y)
return 1;
if (y > x > 1) // Boolean, int error here
// The general case
return (Combinations(y-1, x-1) + Combinations(y-1, x));
}
// Print results of possible combinations
public void print() {
System.out.println(Combinations(y, x));
}
public static void main (String[] args) {
BridgeGame out = new BridgeGame();
Scanner in = new Scanner(System.in);
System.out.println("Please enter X value:");
out.x = in.nextInt();
System.out.println("Please enter Y value:");
out.y = in.nextInt();
out.print();
}
}