Java Program:

- To reverse a number

Example:

User Input: 153

Output:
Your reversed number : 351

import java.util.Scanner;
public class ReverseNumber {
  public static void main(String []args) {
    int num,reverse=0;
    Scanner userInput = new Scanner(System.in);
    System.out.print("Enter Your number : ");
    num = userInput.nextInt();

    while(num!=0) {
      reverse=reverse*10+num%10;
      num/=10;
    }
    System.out.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

The best preparation for good work tomorrow is to do good work today.