We are going to share leap year program in java with the output. If you are a Java beginner and want to start learning the Java programming, then keep your close attention in this tutorial as I am going to share how to write a leap year program in java with the output.
Copy the below Java program and execute it with the help of Javac compiler. At the end of leap year program in java, We have shared the output of this program for better understanding.
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 26 27 28 29 30 31 32 33 34 35 | import java.util.Scanner; public class Demo { public static void main(String[] args) { int year; Scanner scan = new Scanner(System.in); System.out.println("Enter any Year:"); year = scan.nextInt(); scan.close(); boolean isLeap = false; if(year % 4 == 0) { if( year % 100 == 0) { if ( year % 400 == 0) isLeap = true; else isLeap = false; } else isLeap = true; } else { isLeap = false; } if(isLeap==true) System.out.println(year + " is a Leap Year."); else System.out.println(year + " is not a Leap Year."); } } |
Enter any Year:
2000
2000 is a Leap Year.
Liked this program? Do Like & share with your friends.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: Java Programming Examples, Java programs, java programs examples for beginners, java programs examples with output, java programs to practice, Java programs with examples, Java programs with output, java programs with source code, java sample programs for practice, list of java programs