27. JAVA Program To Check Whether The Given Year is Leap Year or Not.
How does this program work?
- In This program your going to learn about how to find the given year is leap year or not.
- By using If else condition here we check the condition for leap year.
- If the given year is exactly divisble by 4 and 400.
- It is denoted as leap year else it not a leap year.
Here is the code
// To check year to leapyear or not.
import java.util.Scanner;public class Leap
{
public static void main(String[] args)
{
//Year to leap year or not
int year;System.out.println("Enter year:");
Scanner obj=new Scanner(System.in);
year=obj.nextInt();
if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
System.out.println(+ year + " is a leap year");
else
System.out.println(+ year + " is not a leap year");
}
}