public final class Pizza { // All the combinartion of topings from none to every one public static void allCombinations (final int[] data) { combinations (data, 0, new int[data.length]); } public static void combinations (final int[] data, final int i, final int[] choices) { if (i==data.length) { // For each topping: include (+1) or exclued (-1) System.out.println (java.util.Arrays.toString(choices)); } else { choices [i] = +1; // Choose to include topping 'i' combinations (data, i+1, choices); choices [i] = -1; // Choose to exclude topping 'i' combinations (data, i+1, choices); choices [i] = 0; // (Reset; makes no difference) } } // List of toppings on command line: e.g., // pepperoni, mushrooms, anchovies, spinach, feta cheese public static void main (final String [] args) { final int [] data = new int [args.length]; System.out.printf ("Combinations of %s%n", java.util.Arrays.toString(args)); allCombinations (data); } }