Write a Kotlin Program to Check Whether a Number is Palindrome or Not

In Kotlin, we can easily check whether a given number is palindrome or not.

A palindrome number is a number that remains the same when its digits are reversed.

For example, 121 is a palindrome number because it remains the same when its digits are reversed.

Here’s the Kotlin program to check whether a number is palindrome or not:

fun main() {
    val number = 121
    var reversed = 0
    var original = number
    
    while (original != 0) {
        val digit = original % 10
        reversed = reversed * 10 + digit
        original /= 10
    }

    if (number == reversed) {
        println("$number is a palindrome number.")
    } else {
        println("$number is not a palindrome number.")
    }
}

In this program, we first declare a variable number and assign it the value of the number we want to check for palindrome.

We also declare two variables reversed and original, where reversed will hold the reversed number and original will hold the original number.

We then use a while loop to reverse the digits of the original number.

In each iteration of the loop, we get the last digit of the original number using the modulus operator and add it to the reversed number.

We then remove the last digit from the original number using integer division.

After the loop is done, we check whether the number and reversed numbers are equal.

If they are equal, we print a message saying that the number is a palindrome number.

Otherwise, we print a message saying that the number is not a palindrome number.

You can replace the value of the number variable with any number you want to check for palindrome. This program will work for both positive and negative numbers.

I hope this Kotlin program helps you check whether a number is palindrome or not.