Kotlin Program to Check Leap Year : In this program, you’ll learn to check if the given year is a leap year or not in Kotlin. This is checked using an if-else statement and a when statement.
Kotlin Program to Check Leap Year
Source Code
fun main(args: Array<String>) {
val year = 1900
var leap = false
if (year % 4 == 0) {
if (year % 100 == 0) {
// year is divisible by 400, hence the year is a leap year
leap = year % 400 == 0
} else
leap = true
} else
leap = false
println(if (leap) "$year is a leap year." else "$year is not a leap year.")
}
Output