# Checking whether a year is leap or not

This tutorial is going to teach you the coding for checking whether a year is a leap year or not.

Tutorials

# Checking whether a year is leap or not

This tutorial is going to teach you the coding for checking whether a year is a leap year or not. Here, we have taken the year 2000. So define an integer n=2000 in the class "Leapyear" and now apply "if else" condition. As we know leap year is divided by the integer 4 and so applying if condition as n/4=0, then "n" is a leap year. Now in the System.out.println write the message that the year is a leap year. Again applying "else" condition the output will be that the year is not a leap year.

Here is the code of program:

 ``` class  Leapyear {   public static void main(String[] args)    {   int n=2000;   if (n%4==0){   System.out.println("The given year is a leap year");   }   else{   System.out.println("This is not a leap year");   } } }```

`Download the program:`

We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

# Checking whether a year is leap or not

Related Tutorials

Discuss: Checking whether a year is leap or not   View All Comments

Subject (*):

Vajrala Rama Rao
June 25, 2011
wrong program

Naresh
September 13, 2011
Wrong Logic

Logic has to be if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) System.out.println("Year " + year + " is a leap year"); else System.out.println("Year " + year + " is not a leap year");
neeraj
September 27, 2011
Bug

this is wrong.....Because 100 is not a leap year Correct logic is if(year%400 ==0 || (year%100 != 0 && year%4 == 0)) { printf("Year %d is a leap year",year); }
Dinesh
November 1, 2011
java Program to find a given year is leap or not?

import java.util.Scanner; public class LeapYearOrNot { public static void main(String[] args) { int n; System.out.println("Enter the year"); Scanner sc = new Scanner(System.in); n = sc.nextInt(); if (n%4 == 0 && n%100!=0||n%400==0) { System.out.println("The given year is a leap year"); } else { System.out.println("This is not a leap year"); } } }
Dni
November 1, 2011
hi,

hi very thankful to u bcz by this prog i got an idea..
dinesh kumar girare
March 13, 2013
leap year

the logic of leap year if(year%4==0) is perfectly not a correct logic so change these correct logic if((year%4==0)&&year%100!=0) { System.out.println("leap year"); } else { if((year%4==0)&&(year%400==0)&&(year%100==0) System.out.println("leap year"); else System.out.println("not leap year"); } } so thanks
brycool
September 21, 2012
java

how to create the leap year program in java
Pritam Patra
November 25, 2012
The same modified with users own input.

package prix; import java.util.Scanner; public class LeapYear { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the year : "); int n = scanner.nextInt(); if (n%4==0){ System.out.println("Congratz! This is a leap year"); } else{ System.out.println("This is not a leap year"); } } }
December 3, 2013
java program

java program not find intheweb