Arrays

In thise example we use String.format to print the number of the month using 2 digits, the name of the month using 10 characters left justified, and the number of days using 2 spaces.

CODE

Output:

# Month     Days
 1 January    31
 2 February   28
 3 March      31
 4 April      30
 5 May        31
 6 June       30
 7 July       31
 8 August     31
 9 September  30
10 October    31
11 November   30
12 December   31

Instead of Print.format we could use printf:

System.out.printf("%2d %-10s %2d%n",mth,month[mth],days[mth]);

Notice that we use %n for a newline.

NEXT: