import java.util.Scanner; public class Spock { private int[] subset; /** * Recursive computation of n choose k * @param n > 0 * @param k <= n * @return the number of possible combinations of * k out of n */ public int combRec(int n, int k){ // pre: 0 <= k <= n // post: return the number of possible combinations of // k out of n if (n==k || k==0) return 1; else // n>k and k>0 return combRec(n-1,k-1) + combRec(n-1,k); } public static void main(String[] args) { // TODO Auto-generated method stub Scanner Input = new Scanner(System.in); int n; Spock S = new Spock(); do{ System.out.println("Enter set size n>0 (0 to finish)"); n = Input.nextInt(); if(n>0) { for(int k = 0; k<=n; k++){ System.out.println("Number of combinations (recursive): (" + n + " choose " +k+ ") = " + S.combRec(n,k)); } } } while (n>0); System.out.println("goodbye Spock"); } }