Write a Kotlin Program to Check Whether a Number is Even or Odd

To check whether a number is even or odd in Kotlin, you can use the modulo operator (%).

If the remainder when the number is divided by 2 is zero, then the number is even, otherwise, it is odd.

Here’s the Kotlin code to check whether a number is even or odd:

fun main() {
    val number = 5
    
    if (number % 2 == 0) {
        println("$number is even.")
    } else {
        println("$number is odd.")
    }
}

In this code, we have a variable number initialized to 5.

We use an if-else statement to check whether the remainder when number is divided by 2 is zero.

If it is, we print that number is even, otherwise, we print that number is odd.

You can replace the value of number with any integer to check whether it is even or odd.

Overall, checking whether a number is even or odd is a simple task in Kotlin, and can be accomplished with just a few lines of code using the modulo operator.