title: Explain creating a pyramid in Java
body: <p>I am in a beginner java programming class and currently reviewing loops.  If there is one thing I just do not understand, it's pyramids.  I have researched the book exercises online and found the solutions to the pyramid examples, but even seeing the code, I still don't understand and couldn't recreate the answers if my life depended on it.  </p>
  
  <p>Below is a pyramid example and the code that creates it.  If someone could walk through the code and give me a line by line 'for dummies' explanation of what is going on then maybe I'll finally understand.</p>
  
  <p>Thanks in advance for you help!</p>
  
  <p>ex.  create the following pyramid:</p>
  
  <blockquote>
  <pre><code>            1
            2 1 2
          3 2 1 2 3
        4 3 2 1 2 3 4
      5 4 3 2 1 2 3 4 5   
    6 5 4 3 2 1 2 3 4 5 6    
  7 6 5 4 3 2 1 2 3 4 5 6 7
  </code></pre>
  </blockquote>
  
  <pre><code>class Pyramid {
  
      public static void main(String[] args) {
  
          int x = 7;
  
          for (int i = 1; i &lt;= x; i++) {
  
              for (int j = 1; j &lt;= x - i; j++)
                  System.out.print("   ");
  
              for (int k = i; k &gt;= 1; k--)
                  System.out.print((k &gt;= 10) ?+ k : "  " + k);
  
              for (int k = 2; k &lt;=i; k++)
                  System.out.print((k &gt;= 10) ?+ k : "  " + k);
              System.out.println();
          }  
      }
  }
  </code></pre>