Thursday, May 24, 2012

Five Fridays in July every 823 years == false


package pkg5fridaysinjuly;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Main {

    private static final int NUMBER_OF_YEARS = 823;

    public static void main(String[] args) {

        Calendar c = new GregorianCalendar();

        int firstYear = c.get(Calendar.YEAR);
        int lastYear = firstYear - NUMBER_OF_YEARS;

        c.set(firstYear, Calendar.JULY, 1);

        System.out.println("Initial: " + firstYear);
        System.out.println("Last: " + lastYear);

        for (int y = firstYear; y >= lastYear; y--) {

            c.set(y, Calendar.JULY, 1);

            if (c.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) {

                System.out.println(y + " Found!");
            }
        }
    }
}

No comments: