title: Generating truth tables in Java
body: <p>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?</p>
  
  <p>So that <code>printTruthTable(1)</code> prints:</p>
  
  <pre><code>0
  1
  </code></pre>
  
  <p><code>printTruthTable(3)</code> prints:</p>
  
  <pre><code>0 0 0
  0 0 1
  0 1 0
  0 1 1
  1 0 0
  1 0 1
  1 1 0
  1 1 1
  </code></pre>
  
  <p>And so on. I have been trying to implement it using recursion, but I just can't get it right.</p>