Determining whether a particular year is a leap year in Java

The rule is that all years divisible by 4 are leap years. An exception is when the year is divisible by 100 unless the year is also divisible by 400.

On a GreorianCalendar instance, you can invoke the method isLeapYear.

Main.java:

import java.util.*;
 
public class Main {
   public static void main(String args[]) {
      GregorianCalendar calendar = new GregorianCalendar();
 
      for (int i=1990; i<2010; i++) {
         System.out.println(i + ": " + (calendar.isLeapYear(i) ? "yes" : "no"));
      }
   }
}

outputs:

1990: no
1991: no
1992: yes
1993: no
1994: no
1995: no
1996: yes
1997: no
1998: no
1999: no
2000: yes
2001: no
2002: no
2003: no
2004: yes
2005: no
2006: no
2007: no
2008: yes
2009: no