title: What is the logic to print the below mentioned number pattern
body: <pre><code>class Num {
      public static void main(String[] args) {
          for(int i=1;i&lt;=5;i++) {
              for(int j=1;j&lt;=i;j++) {
                  if(j==1) {
                      System.out.print(i);
                  }
                  else if(j==2) {
                      System.out.print(" "+(i+j+2));
                  }
                  else {
                      System.out.print(" "+(i+j+4));
                  }
              }
              System.out.println(" ");
          }
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>1
  2 6
  3 7 10 
  4 8 11 12
  5 9 12 13 14
  </code></pre>
  
  <p>Expected:</p>
  
  <pre><code>1
  2 6
  3 7 10 
  4 8 11 13
  5 9 12 14 15
  </code></pre>
  
  <p>I tried so much and came up with this logic</p>
  
  <pre><code>when j=1 then i
  when j=2 then i+j+2
  when j=3 then i+j+4
  when j&gt;=4 then i+j+5
  </code></pre>
  
  <p>there are totally 4 conditions here, how do i get do this in nested for loop. Any other logic is also appreciable.</p>