In this post, we will see how to check leap year.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import java.util.Scanner; public class LeapYearFinder { public static void main(String args[]) { int year; Scanner scanner = new Scanner(System.in); System.out.print("Enter Year : "); year = scanner.nextInt(); if((year%4 == 0) && (year%100!=0)){ System.out.print(year+" is a Leap Year"); }else if(year%100 == 0){ System.out.print(year+" is not a Leap Year"); }else if(year%400 == 0){ System.out.print(year+" is a Leap Year"); }else{ System.out.print(year+" is not a Leap Year"); } } } |
Output:
Enter Year : 2018
2018 is not a Leap Year
2018 is not a Leap Year
That’s all about Java program to check leap year.
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.