/* This program demonstrates probably the simplest use of 2D arrays */ public class multtable { public static void main(String[] args) { // declare the 2D array, which will hold a multiplication table int[][] multtable = new int[10][10]; // fill the array with data for(int i=0; i<10; i++) { // this loop is for rows for(int j=0; j<10; j++) { // this loop is for columns multtable[i][j] = i*j; } } // same loops as before, but now we just print out the arrays // notice that we start the loops at 1 this time, because we don't need to see // a row of all zeros for(int i=1; i<10; i++) { for(int j=1; j<10; j++) { // this ensures that all single-digit numbers will line up into columns if(multtable[i][j] < 10) System.out.print(" "); System.out.print(multtable[i][j]+" "); } // make a new line for every row System.out.print("\n"); } } }