title: Printing all permutations of True and False
body: <p>I want to make a program that prints all permutations of true and false based on X length that is entered by the user. What I did was first initialize an array X elements long and initialize them all to true. Then I cycle thorough them to make the different permutations. The output is the array with all true and then it just prints false and the rest true eg</p>
  
  <pre><code>If X (length was 2)
  
  true  true
  false true
  false true
  false true
  </code></pre>
  
  <p>Here is my code.</p>
  
  <pre><code>import hsa.Console;
  
  public class TorF {
  
  public static void main (String[] args) {
  
      Console c = new Console();
  
      c.print("Length: ");
      int l = c.readInt();
  
      boolean[] values = new boolean[l];
  
      for (int i = 0; i &lt; values.length; i++) {
  
          values[i] = true;
      }
  
      int numberOfPremutations = (int) Math.pow (2, l);
  
      for (int j = 0 ; j &lt; numberOfPremutations ; j++) {
  
          for (int i = 0 ; i &lt; l ; i++)
              System.out.print (values [i]);
  
          System.out.println ("");
  
          values[l - 1] = false;
  
          for (int i = l - 1 ; i &gt; 0 ; i--) {
  
              if (values [i] == false) { 
                  values [i - 1] = false;
                  values [i] = true;
  
  
              }
          }
  
      }       
  
  }
  
  }
  </code></pre>