title: How do I write a program to output a triangle of numbers in Java?
body: <p>I need help. My assignment is to write a Java program using nested loops to print out the following output pattern:</p>
  
  <pre><code>                   1 
                   1 2 1 
                  1 2 4 2 1 
                1 2 4 8 4 2 1 
              1 2 4 8 16 8 4 2 1 
            1 2 4 8 16 32 16 8 4 2 1 
         1 2 4 8 16 32 64 32 16 8 4 2 1 
      1 2 4 8 16 32 64 128 64 32 16 8 4 2 1 
  </code></pre>
  
  <hr>
  
  <pre><code>//pattern1
  for(int outer=1;outer&lt;=6;outer++) // outer loop controls number of rows
  {
      for(int inner=1;inner&lt;=outer; inner++) // another loop to control number of numbers in each row.
      {
          System.out.print(inner);
      }
      System.out.println(); // move the cursor from the end of the current line to the beggiing to the next line
  }
  
  //pattern 2
  for(int outer =1; outer&lt;=6 ; outer++) //outer loop controls number of rows
  {
      //3-1 create spaces before numbers.
      for(int space=1; space&lt;=6-outer; space++ ) //group controls number of spaces
      {
          System.out.print(" ");
      }
  
      //3-2 print out real numbers.
      for(int inner=1;inner&lt;=outer; inner++) // another loop to control number of numbers in each row.
      {
          System.out.print(inner);
      }
      System.out.println();
  }
  </code></pre>
  
  <p>Those two codes are back to back, but I do not understand how I would make the numbers <code>2 4 8 16</code> etc show up, and put them back to back. </p>
  
  <p>What's wrong with my code? Is there a better way of doing this in Java?</p>