Java Program to Check given year is leap year or not

0
Share

In this program, you’ll learn to Check given year is leap year or not in Java. After write the code, the final output is displayed on the screen.

Example -1 Check given year is leap year or not

import java.util.*;
public class Leapyear{
    public static void main(String arg[]){
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the year : ");
        int year=sc.nextInt();
        if((year%400==0) || (year%4==0 && year%100!=0)){
            System.out.println("Leap year");
        }
        else{
            System.out.println("Not a leap year");
        }
        }
    }

Example 2

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

Output

Enter the year : 2021
Not a leap year

Read more post

  • What are the List of CSS3 New Features ?
    CSS3 is the latest version of the normal CSS . CSS3 adds several new styling features and improvements to enhance the web presentation capabilities. Text Effect in...
  • CSS Basic Property
    What is CSS ? CSS stands for Cascading Style Sheets. CSS basically used in designing the web tags & pages. CSS is the most popular used...
  • Java Program to swap two number use 3rd variable
    In this program, you’ll learn to Program to swap 2 number with 3rd variable in Java. After write the code, the final output is displayed on...
  • Java program to multiply two floating point number
    In this program, you’ll learn to Program to multiply two floating point number in Java. After write the code, the final output is displayed on the...
  • Java Program to find the ASCII value of a character
    In this program, you’ll learn to Program to find the ASCII value of a character in Java. After write the code, the final output is displayed...
  • Java Program to calculate quotient & reminder
    In this program, you’ll learn to Given Number is even or odd in Java. After write the code, the final output is displayed on the screen....
%d bloggers like this: