Kotlin Program to Check Leap Year

In this post, we will learn how to write a Kotlin Program to check Leap year.

Kotlin Program to Check Leap Year

package com.kotlin.programs

fun main(args: Array < String > ) {

    val year = 2019
    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:
2019 is not a leap year.






Comments