Write a kotlin program to reverse a number using recursive methods

Write a program to reverse a number using numeric operations. The below example shows how to reverse a number using numeric operations.

fun reverseNumber(number: Int): Int {
    var number = number

    var reverse = 0
    while (number != 0) {
        reverse = reverse * 10 + number % 10
        number = number / 10
    }
    return reverse
}


fun main(a: Array<String>) {
    var num = 12346598
    println("Original Number : " + num)
    println("Reversed Number : " + reverseNumber(num))
}


Output

Original Number : 12346598
Reversed Number : 89564321
About Author :

I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions