Leap Year Program in java

What is a leap year?

The year is a leap year if it is divisible by 400 or divisible by 4 but not divisible by 100.

Steps to check leap year in java:-

  • Take input from the user using a scanner.
  • check if the given year is divisible by 400, if this condition is true then the given year is a leap year.
  • check else if the year is divisible by 4 but not divisible by 100, if this condition is true then the given year is a leap year.
  • else given year is not a leap year.

Leap year program in java:-

import java.util.Scanner;
public class LeapYear {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("Enter the year");
            int year= sc.nextInt();
            if(year%4==0 && year%100 !=0) {
                System.out.println("Yes");}
            else if(year%400==0){
                System.out.println("Yes");}
            else {
                System.out.println("Not");}
        }}
leap year in Java

Similar Java Tutorials

1 thought on “Leap Year Program in java”

Leave a Comment