Reverse of 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

    println("Reverse of $tempNumber=$reverse")//9
  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 tempNumbr 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 multiply 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. Print the reverse number of the entered number on the console

Enter a Number
Reverse of 2345=5432

Leave a Reply

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