Skip to content

Instantly share code, notes, and snippets.

@BT-ICD
Created January 24, 2021 18:09
Show Gist options
  • Save BT-ICD/2f150f0e7c1619e9df8dcb5fcc334fe7 to your computer and use it in GitHub Desktop.
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.
/**
* 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