Skip to Content

Determine If Year Is Leap Year Java Example

  1. /*
  2.         Determine If Year Is Leap Year Java Example
  3.         This Determine If Year Is Leap Year Java Example shows how to
  4.         determine whether the given year is leap year or not.
  5. */
  6.  
  7. public class DetermineLeapYearExample {
  8.  
  9.         public static void main(String[] args) {
  10.                
  11.                 //year we want to check
  12.                 int year = 2004;
  13.                
  14.                 //if year is divisible by 4, it is a leap year
  15.                
  16.                 if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
  17.                         System.out.println("Year " + year + " is a leap year");
  18.                 else
  19.                         System.out.println("Year " + year + " is not a leap year");
  20.         }
  21. }
  22.  
  23. /*
  24. Output of the example would be
  25. Year 2004 is a leap year
  26. */