Java Program to Check Leap Year

In this example, we are giving a program to check a year is leap year or not.


To check a year is leap year or not:

  1. # To check a year is leap year or not
  2. public class Largest {
  3. public static void main(String[] args) {
  4. int year = 2019;
  5. boolean leap = false;
  6. if (year % 4 == 0) {
  7. if (year % 100 == 0) {
  8. if (year % 400 == 0)
  9. leap = true;
  10. else
  11. leap = false;
  12. }
  13. else
  14. leap = true;
  15. }
  16. else
  17. leap = false;
  18. if(leap)
  19. System.out.println(year + " is a leap year.");
  20. else
  21. System.out.println(year + " is not a leap year.");
  22. }
  23. }

Output:

2019 is not a leap year.