previous | start | next

The main method

Line 3: delcares and creates the two dimensional array.

Line 5: jumble.length is the number of rows

jumble[0] is the entire first row. jumble[1] is the entire second row, etc., jumble[0][0] is the first character in row 0, jumble[1][0] is the first character in row 1.

Line 6: jumble[0].length is the number of elements in row 0. This is the same as jumble[1].length since all rows have the same number of elments (5). This is also the number of columns.

Line 7: This expression will generate a random letter in the range 'A' - 'Z'.

      (char) ('A' + r.nextInt(26))
   
    1     public static void main(String[] args)
    2     {
    3       char jumble[][] = new char[3][5];  // 3 rows, 5 columns
    4       Random r = new Random();
    5       for(int row = 0; row < jumble.length; row++) {
    6         for(int col = 0; col < jumble[0].length; col++) {
    7           jumble[row][col] = (char) ('A' + r.nextInt(26));
    8         }
    9       }
   10   
   11       printArray2(jumble);
   12   
   13     }


previous | start | next