title: Can someone explain how Java nested loops work with number patterns?
body: <p>I am having trouble understanding how nested loops and numbers patterns work. I have completed all of the patterns except 3. Can someone please help me with this code and explain how this works?</p>
  
  <pre><code>public class Patterns7{
      public Patterns7() {
      }
  
      public void displayPatternI(int lines) 
      {
          System.out.println("\n\tPattern I\n");
          for (int i = 1; i &lt;= lines; i++)
          {
              for (int j = 1; j &lt;= i; j++)
                  System.out.print (j + " " );
              System.out.println();
          }
      }
  
      public void displayPatternII (int lines) 
      {
          System.out.println("\n\tPattern II to be implemented\n");
          for (int i = 1;i &lt;= lines; i++) 
          { 
              for(int j = i;j &gt;= 1; j--) 
                  System.out.print(j); 
  
              System.out.println(); 
          }
          System.out.println();
      }
  
      public void displayPatternIII (int lines) 
      {
          System.out.println("\n\tPattern III  to be implemented\n");
          for (int i = 1; i &lt;= lines; i++)
          {
              for (int space = 1; space &lt;= lines-i; space++)
                  System.out.print (" ");
  
              for (int j = 1; j &lt;= i; j++)
                  System.out.print (j + " ");
  
              System.out.println();
          }
  
          System.out.println();
      }
  }
  </code></pre>
  
  <p>Pattern III is supposed to look like this:</p>
  
  <pre><code>      6
  
       56
  
      456
  
     3456
  
    23456
  
   123456
  </code></pre>
  
  <p>But all I could get it to do was this:</p>
  
  <pre><code>      1
  
       1 2
  
      1 2 3
  
     1 2 3 4
  
    1 2 3 4 5
  
   1 2 3 4 5 6
  </code></pre>
  
  <p>I am unsure of how to get the out put to start with 6 and decrease then increase.</p>
  
  <p>Pattern V is supposed to look like this:</p>
  
  <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
  </code></pre>
  
  <p>But it comes out like this:</p>
  
  <pre><code>    1
  
       1 2 3
  
      1 2 3 4 5
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>public void displayPatternVI (int lines) 
  {
      System.out.println("\n\tMy Own Pattern to be implemented\n");
  
      for (int i = 1; i &lt;= lines/2; i++)
      {
          for (int space = 1; space &lt;= (lines/2)-i; space++)
              System.out.print (" ");
  
          for (int j = 1; j &lt;= (i*2)-1; j++)
              System.out.print (j + " ");
  
          System.out.println();
      }
  
      for (int i = 1; i &lt;= lines/2; i++)
      {
          for (int space = 1; space &lt;= i-1; space++)
              System.out.print (" ");
  
          for (int j = 1; j &lt;= lines-(i*2)+1; j++)
              System.out.print (j + " ");
  
          System.out.println();
      }
  
      System.out.println();
  }
  </code></pre>
  
  <p>Pattern VI is supposed to look like this:</p>
  
  <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
  
      6 5 4 3 2 1 2 3 4 5 6
  
        5 4 3 2 1 2 3 4 5 
  
          4 3 2 1 2 3 4
  
            3 2 1 2 3
  
              2 1 2
  
                1
  </code></pre>
  
  <p>but it looks like this:</p>
  
  <pre><code>      1
  
       1 2 3
  
      1 2 3 4 5
  
      1 2 3 4 5
  
       1 2 3
  
        1
  </code></pre>
  
  <p>Can someone please help and explain to me how to this?</p>