title: Java: How to output all possible binary combinations (256 different sequences)?
body: <p>I need to create a function that outputs all possible binary combinations (2^8 == 256 different sequences of 8 bits.). I'm really stumped on this. I have to do it with nested loops, and am not sure how to go about it. Below is what I tried so far. I was told that I could write this program using 8 nested loops, each one going from 0 to 1; Also, I could try to do this with bit manipulation operators. </p>
  
  <p>Although what I have below is obviously wrong, I tried my best to show that I at least tried this. I also need to put new line's after each closing bracket, to separate the output.</p>
  
  <p><strong>The output should look like this:</strong></p>
  
  <p>00000000</p>
  
  <p>00000001</p>
  
  <p>00000010</p>
  
  <p>00000011</p>
  
  <p>00000100</p>
  
  <p>...</p>
  
  <p>11111110</p>
  
  <p>11111111</p>
  
  <pre><code>public static void outputBinary(){
  
  int[][][][][][][][] num = new int[2][2][2][2][2][2][2][2];
  
      for (int i = 0; i &lt; 2; i++){
  
      for (int j = 0; j &lt; 2; j++){
  
      for (int k = 0; k &lt; 2; k++){
  
      for (int l = 0; l &lt; 2; l++){
  
      for (int m = 0; m &lt; 2; m++){
  
      for (int n = 0; n &lt; 2; n++){
  
      for (int o = 0; o &lt; 2; o++){
  
      for (int p = 0; p &lt; 2; p++){
  
          System.out.print(num[i][j][k][l][m][n][o][p]);
  
      } }}}}}}}
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Thanks for looking.</strong></p>