func leapYear(_ year: Int) {
if year % 4 == 0 {
if year % 100 == 0 && year % 400 != 0 {
print("\(year) - Not a leap year!")
} else {
print("\(year) - Leap year!")
}
} else {
print("\(year) - Not a leap year!")
}
}
HI all! I apologise if question is simple (I'm a complete beginner in programming). I want to enter "leapYear(2021)" and I want to see that given year is leap year or not. I want to make this code short and the question is why if I remove last else I do not get output: "2021 - Not a leap year!"
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: