Kotlin Program to Check Whether a Number is Even or Odd

Kotlin Program to Check Whether a Number is Even or Odd: In this program, you’ll learn to check if a number entered by a user is even or odd. This will be done using two variants of if…else in Kotlin.

Kotlin Program to Check Whether a Number is Even or Odd

Source Code

import java.util.Scanner

fun main(args: Array<String>) {

  var n: Int

    var sc = Scanner(System.`in`)

    print("Enter a Number :")
    n = sc.nextInt()

    if (n % 2 == 0) {
        println("$n is Even")
    } else {
        println("$n is Odd")
    }
}

Output