Kotlin Program:

- To reverse a number

Example:

User Input: 153

Output:
Your reversed number : 351

import java.util.Scanner
fun main(args: Array<String>) {
  print("Enter your number : ")
  val userInput = Scanner(System.`in`)
  var num:Int = userInput.nextInt()
  var reverse:Int = 0

  while(num!=0) {
    reverse=reverse*10+num%10;
    num/=10;
  }
  println("Your reversed number : $reverse")
}

Output:

  Enter Your number : 1132
  Your reversed number : 2311
Program
number

Main Logic :

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

Example :

Initially, reverse=0
Let num=15,

Now, reverse=0,num=15 [still 'num' not equal to ZERO]
reverse = 0*10+15%10; // = 5
num=15/10;  // =1;

Now, reverse=5,num=1 [still 'num' not equal to ZERO]
reverse=5*10+1%10;   // =51
num=1/10;  // =1

Now num=0
So finally your reverse number which is 51
Concept

Coming Soon !

Quick
Tutorial

Quote

A good decision is based on knowledge and not on numbers.