// create array using 1D arrays public class aoa0 { public static void main(String args[]) { // Create ragged array with default values: final int ROWS = 2; int[][] a = new int[ROWS][]; // Create array $r0$ to store values 1 and 2: int[] r0 = new int[2]; r0[0] = 1; r0[1] = 2; // also, int[] r0 = {1,2}; // Create array $r1$ to store values 3, 4, 5: int[] r1 = new int[3]; r1[0] = 3; r1[1] = 4; r1[2] = 5; // Store refs to arrays $r0$ and $r1$ in // 1st and 2nd elements of array $a$: a[0] = r0; a[1] = r1; // Use $a[i][j]$ to access elements: for ( int i=0 ; i < a.length ; i++) { // "rows" for ( int j = 0 ; j < a[i].length ; j++) // "cols" System.out.print(a[i][j] +" ") ; // element System.out.println(); // skip lines between rows } } // method main } // class aoa0 /* output: 1 2 3 4 5 */