Last active
October 23, 2024 18:46
-
-
Save TheMuellenator/5343c658efdd46dc04522174fa4f0cd1 to your computer and use it in GitHub Desktop.
iOS repl.it - IF Else Challenge Solution
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
//Don't change this | |
var aYear = Int(readLine()!)! | |
func isLeap(year: Int) { | |
var leap = "NO" | |
//IF divisible by 4 with no remainders. | |
if year % 4 == 0 { | |
leap = "YES" | |
//Is leap year, unless: | |
} | |
if year % 100 == 0 { | |
leap = "NO" | |
//Is not leap year, unless: | |
} | |
if year % 400 == 0 { | |
leap = "YES" | |
//Is leap year. | |
} | |
print(leap) | |
} | |
//Don't change this | |
isLeap(year: aYear) |
func isLeap(year: Int) {
if year % 4 == 0 && (year % 100 != 0 || year % 400 == 0) {
print("YES")
}
else{
print("NO")
}
}
var aYear = 2020
func isLeap(year: Int) {
if year % 4 == 0 && year % 100 != 0 {
print("Yes, Leap Year")
} else if year % 100 == 0 && year % 400 == 0 {
print("Yes, A leap year")
} else {
print("No, Not a leap year")
}
}
isLeap(year: aYear)
Check my answer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So here the "==0" is calculate based on the modulus (remainder). Using the example 2000%4 which means that how many multiples of 4 will fit inside the value 2000 and returns the value that's left over which is 0 in this case.
More details check the screenshot below:

In the screenshot you can see at Line89 that the remainder of 2000%4 is 0 as there is no remainder.
If there is anything feel free to ask.
Thanks.