title: Cant get required output from loop
body: <p>I am trying to get a certain output pattern from the array but can't seem to get what I'm looking for and now sure why. Link is the desired output. Sorry if formatting is not good. Array size is inputted by the user.</p>
  
  <pre><code>public class A3_Q2 { 
  
      int [][] pattern2 = new int[arraySize][arraySize];
  
      number = 1;
      int i;
      int j;
      int newNumber = arraySize-1;
  
      for (i = 0; i &lt; arraySize; i++) 
  
      {
  
          if (i == 0)
          {
  
              for (j = 0; j &lt; arraySize; j++)
              {
                  pattern2[i][j] = number;
                  System.out.printf("%3d", pattern2[i][j]);
                  number++;
              }
  
          }
  
          else 
          {
              for(j = 0; j &lt; i; j++)
              {
                  pattern2[i][j] = number + newNumber;
                  System.out.printf("%3d", pattern2[i][j]);
                  newNumber++;
              }
              newNumber = arraySize-1;
              while(j &lt; arraySize)
              {
                  pattern2[i][j] = number;
                  System.out.printf("%3d", pattern2[i][j]);
                  number++;
                  j++;
              }
  
  
          }
          System.out.println(""); 
     }
  </code></pre>
  
  <p>Desired Output:</p>
  
  <pre class="lang-none prettyprint-override"><code>  1  2  3  4  5
   10  6  7  8  9
   14 15 11 12 13
   18 19 20 16 17
   22 23 24 25 21
  </code></pre>
  
  <p>This image shows the out-of-sequence cells highlighted:</p>
  
  <p><img src="https://i.stack.imgur.com/SS4xX.png" alt="Desired Output"></p>