The source code is about to check the whether the year is leap year not. This was developed using java.
By this program we will learn about how to check whether the year is leap year or not. Leap year is divisible by 4 which has exactly 366 days with 29 days in February. Century years are to be considered as leap years only if it is divisible by 400. This program uses if..else statements to check the condition.
Explanation of source code
public class Main {
public static void main(String[] args)
int year = 2005;
boolean leap = false;
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0)
leap = true;
else
leap = false;
}
else
leap = true;
}
else
leap = false;
if (leap)
System.out.println(year + " This year is a leap year.");
else
System.out.println(year + " This year is not a leap year.");
}
}
Submitted by Kajjayam Priya (Priya1414)
Download packets of source code on Coders Packet
Comments