Number pattern problem using Java
Since all you've been asked is to display output, a single simple nesting of two for loops without arrays should work just fine. Note that in all cases, you know in advance prior to performing a loop how many times the loop will iterate, and in this situation a for loop is cleaner than a while loop (though of course both would work):

// note that method namess should begin with a lower-case letter
public static void numberPattern(int rows) {
  for (int row = 0; row &lt; rows; row++) {
     for (int col = 0; col &lt; rows + 1; col++) {
        int number = 0;
        if (row % 2 == 0) {
           number = col &lt; rows ? row + 1 : row + 2;
        } else {
           number = col == 0 ? row + 2 : row + 1;
        }
        System.out.print(number);
     }
     System.out.println();
  }
}


If you need to store the numbers to be used elsewhere, then yes, put them into an array.