Thursday, March 1, 2012

Leaf year in java


Following code can be used to find Leaf Year in java.

public boolean isLeafYear(int year) {
        boolean leaf = false;
        if (year < 100) {
            if (year > 40) {
                year = year + 1900;
            } else {
                year = year + 2000;
            }
        }
        if (year % 4 == 0) {
            if (year % 100 != 0) {
                leaf = true;
            } else if (year % 400 == 0) {
                leaf = true;
            }
        }
        return leaf;
    }