import java.util.Scanner; public class Spock { public static int C(int n, int k) // Preconditions: 0 <= k <= n // Postcondition: return n-choose-k, the number of subsets of size k of // a set of n planets { // only one way not to choose any of them; // only one way to choose all of them ... if (k == 0 || k == n) return 1; else return C(n-1,k-1) // choose Planet X and count ways of choosing // remaining k-1 from remaining n-1 planets + C(n-1,k); // don't choose Planet X and count ways of // choosing k from remaining n-1 planets } public static void main(String[] args) { Scanner Input = new Scanner(System.in); System.out.print("Enter number of planets to choose from: "); int n = Input.nextInt(); System.out.print("Enter number he can visit: "); int k = Input.nextInt(); System.out.println("\n\nThere are " + C(n,k) + " ways to choose " + k + " of the planets\n"); } }