India's Largest Free Online Education Platform

Java program to check leap year

Java program to check leap year

Code:

import java.util.Scanner;
    public class Leap_Year
    {
        public static void main(String args[])
        {
            System.out.println("Enter any year to know is it leap year or not");
            Scanner Sc=new Scanner(System.in);
            int year= Sc.nextInt();
            if(year%4==0)
            {
                if (year % 100 == 0)
                {
                    if (year % 400 == 0)
                        System.out.println("leap year");
                    else
                        System.out.println("Not leap year");
                } else
                    System.out.println("Leap year");
            }
            else
                System.out.println("Not leap year");
        }
    }

Output:01

Output:02

Output:03

Output:04

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!