Kotlin Program:

- To check number is Palindrome or not

Example:

User Input: 1221

Output: Palindrome Number

import java.util.Scanner
fun main(args: Array<String>) {
    
  val userInput = Scanner(System.`in`)
  print("Enter your number : ")
  var num:Int = userInput.nextInt()
  var reverse:Int = 0
  var num2:Int = num
  while(num!=0) {
    reverse=reverse*10+num%10
    num/=10
  }

  if(num2==reverse)println("Palindrome Number")
  else println("Not a Palindrome Number")

}

Output:

  Enter Your number : 12321
  Palindrome Number
Program
number

You must know first,

Palindrome Number : if a number & reverse of it are equal then the number is Palindrome number

Example :

Number: 121 & its Reverse = 121 . so it's Palindrome
Number: 123 & its Reverse = 321 . so it's NOT a Palindrome

//Save the original number
  num2=num

//reverse the number
  while(num!=0) {
  reverse=reverse*10+num%10
  num/=10
}

//check for the Palindrome
if(num2==reverse)
Concept

Coming Soon !

Quick
Tutorial

Quote

Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning.