Palindrome Number

fun main() {
    println("Enter a Number")//1
    var number = readLine()!!.toInt()//2
    var reverse = 0//3
    val tempNumber = number//4
    while (number != 0) {//5
        val digit = number % 10//6
        reverse = reverse * 10 + digit//7
        number = number / 10//8

    }
   if(tempNumber==reverse)//9
   {
       println("Enter Number $tempNumber is Palindrome Number")//10
   }
   else
   {
       println("Enter Number $tempNumber is not Palindrome Number")//11
   }

}


  1. Instruct the user to enter a number
  2. Convert user enter a value into int and assign to number variable
  3. Create and initialize a reverse variable with 0 value
  4. Create and initialized tempnumber with the number variable
  5. Execute while loop til number value is 0
  6. Calculate the value of digit variable and assign after calculating the mode of the number variable
  7. Calculate the value of the reverse variable after multiplying the reverse Value by 10 and adding digit in multiplication
  8. Calculate the new value of a number by divider the old value to 10
  9. If Statement to check reverse value and tempnumber values are same
  10. Execute the if Block when if the statement is true and print the output on the console
  11. Execute the else block when if statement result is false and print the output on the console

Leave a Reply

Your email address will not be published. Required fields are marked *