I'm trying to print some truth tables as part of a school assignment. How can I generate a dynamic size truth table in Java?
So that printTruthTable(1)
prints:
0
1
printTruthTable(3)
prints:
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
And so on. I have been trying to implement it using recursion, but I just can't get it right.
If you look at what you're generating, it appears to be counting in binary. You're going to be counting to 2^(n) - 1 in binary and spitting out the bits.