Home Java Beginners Checking whether a year is leap or not



Checking whether a year is leap or not
Posted on: February 11, 2008 at 12:00 AM
This tutorial is going to teach you the coding for checking whether a year is a leap year or not.

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:

Related Tags for Checking whether a year is leap or not:
cideclassdiviointegerprintoutputsystemviintmessageidaiwriteappdefineifconditioneareilitnotlsputapplyinnoasmntoutsagelnleapyearclesemagemeppsysyearsssasoessatplykishallivdivideeaandar2000sassrithcondavstaphateapfingaintlplprndono


More Tutorials from this section

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

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.