Skip to content

Instantly share code, notes, and snippets.

@hellofaizan
Created November 9, 2021 01:28
Show Gist options
  • Save hellofaizan/8d8c97da888a46adfdf646cf2cf14c29 to your computer and use it in GitHub Desktop.
Save hellofaizan/8d8c97da888a46adfdf646cf2cf14c29 to your computer and use it in GitHub Desktop.
Algorithms behind checking whether any given year is leap year or not | Curious Faizan
public class Main {
public static void main(String[] args) {
// year to be checked
int year = 1996;
boolean leap = false;
// if the year is divided by 4
if (year % 4 == 0) {
// if the year is century
if (year % 100 == 0) {
// if year is divided by 400
// then it is a leap year
if (year % 400 == 0)
leap = true;
else
leap = false;
}
// if the year is not century
else
leap = true;
}
else
leap = false;
if (leap)
System.out.println(year + " is a leap year.");
else
System.out.println(year + " is not a leap year.");
}
}
@hellofaizan
Copy link
Author

Version 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment