Created
March 7, 2013 20:07
-
-
Save lordhumunguz/5111328 to your computer and use it in GitHub Desktop.
Leap year method
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
#Leap years are divisible by 4 (like 1992 and 1996). | |
#There is an exception, though, and an exception to the exception: | |
#if a year is divisible by 100, it's not a leap year (like 1900), | |
#unless it is also divisible by 400 (like the year 2000). | |
def leap_year? (year) | |
if year%100 == 0 && year%400 == 0 | |
puts "Leap Year!" | |
elsif year%4 == 0 && year%100 != 0 | |
puts "Leap Year!" | |
else | |
puts "Not Leap Year!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment