Created
November 9, 2021 01:28
-
-
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
This file contains hidden or 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
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."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version 1