Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.ArrayList;

public class Main {
    private static void fillCombinations(ArrayList<Boolean> current, ArrayList<ArrayList<Boolean>> result, int n) {
        // base case
        if (current.size() == n) {
            result.add(current);
        } else {
            // add a zero
            ArrayList<Boolean> addZero = new ArrayList(current);
            addZero.add(false);
            fillCombinations(addZero, result, n);

            // add a one
            ArrayList<Boolean> addOne = new ArrayList(current);
            addOne.add(true);
            fillCombinations(addOne, result, n);

        }
    }
}