"KEEP LEARNING, DON'T STOP."
"KEEP LEARNING, DON'T STOP."
In this section you will learn how to check whether a year is leap year or not. Just simple mathematic operation we will perform to check the leap year. In this program we are taking the year as input from the user.
A leap year is a calendar year containing one additional day. Leap years are needed to keep our modern day in alignment with the Earth's revolutions around the sun.
Scanner function is use to take the input from user in java.
import java.util.Scanner; class LeapYear { public static void main(String arg[]) { int n; Scanner sc = new Scanner(System.in); System.out.println("ENTER A YEAR:- "); n = sc.nextInt(); if(n%4==0) { System.out.println("GIVEN YEAR IS LEAP YEAR."); } else { System.out.println("GIVEN YEAR IS NOT A LEAP YEAR."); } } }
ENTER A YEAR:- 2016 GIVEN YEAR IS LEAP YEAR.
Advertisment