// BadLuckDays.java (c) Kari Laitinen // http://www.naturalprogramming.com // 2014-11-24 Java file created. // 2014-12-30 Last modification. // This version of the Friday13.java program uses the new // time-related class LocalDate (available in Java 1.8 and later.) import java.time.* ; class BadLuckDays { public static void main( String[] not_in_use ) { LocalDate date_of_today = LocalDate.now() ; // First we create a LocalDate object that contains the 13th day // of current month. This program can also print this, possibly // past, date. LocalDate date_to_check = LocalDate.of( date_of_today.getYear(), date_of_today.getMonthValue(), 13 ) ; int number_of_friday13_dates_to_print = 10 ; System.out.print( "\n The following are Fridays which also are" + "\n the 13th days of a month: \n\n" ) ; while ( number_of_friday13_dates_to_print > 0 ) { if ( date_to_check.getDayOfWeek() == DayOfWeek.FRIDAY ) { System.out.printf( " %1$tF, %1$tA\n", date_to_check ) ; number_of_friday13_dates_to_print -- ; } // The following statement creates a new LocalDate object that // contains the 13th day of the following month. date_to_check = date_to_check.plusMonths( 1 ) ; } } }