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.
Math.pow(2,n)
with(1 << n)
– Pantalets