// WeddingdatesGregorianCalendar.java (c) 2005 Kari Laitinen // http://www.naturalprogramming.com // 2005-06-14 File created. // 2005-06-14 Last modification. // A solution to exercise 15-8. import java.util.* ; class WeddingdatesGregorianCalendar { public static void main( String[] not_in_use ) { Calendar date_to_increment = new GregorianCalendar() ; int number_of_dates_printed = 0 ; System.out.print( "\n These are easy-to-remember dates for weddings and" + "\n other important events because the days and months" + "\n consist of the digits used in the year: \n" ) ; while ( number_of_dates_printed < 60 ) { String day_as_string = String.format( "%02d", date_to_increment.get( Calendar.DAY_OF_MONTH ) ) ; String month_as_string = String.format( "%02d", date_to_increment.get( Calendar.MONTH ) + 1 ) ; String year_as_string = "" + date_to_increment.get( Calendar.YEAR ) ; if ( year_as_string.indexOf( day_as_string.charAt( 0 ) ) != -1 && year_as_string.indexOf( day_as_string.charAt( 1 ) ) != -1 && year_as_string.indexOf( month_as_string.charAt( 0 ) ) != -1 && year_as_string.indexOf( month_as_string.charAt( 1 ) ) != -1 ) { // Now we have found a date that meets our requirements. if ( number_of_dates_printed % 5 == 0 ) { System.out.print( "\n" ) ; } System.out.printf( " %1$tm/%1$td/%1$tY", date_to_increment ) ; number_of_dates_printed ++ ; } date_to_increment.add( Calendar.DAY_OF_MONTH, 1 ) ; } } }