Created
January 24, 2021 18:09
-
-
Save BT-ICD/2f150f0e7c1619e9df8dcb5fcc334fe7 to your computer and use it in GitHub Desktop.
Conditional Execution Demo- To determine particular year is a leap year or not.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* To determine that particular year is a leap year or not | |
* Note: | |
* A year is a leap year if the following conditions are satisfied: | |
* The year is multiple of 400. | |
* The year is multiple of 4 and not multiple of 100. | |
* According to these rules, the years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300, and 2500 are not leap years. | |
* References: | |
* https://www.timeanddate.com/date/leapyear.html | |
* https://www.wikihow.com/Calculate-Leap-Years | |
* */ | |
public class LeapYearExample { | |
public static void main(String[] args) { | |
int year=2000; | |
if(((year%4==0) && (year%100!=0)) || (year%400==0)){ | |
System.out.println(year + " is a leap year"); | |
} | |
else{ | |
System.out.println(year + " is not a leap year"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment