Write a java program to reverse a number and output it.


A number in java can be reversed in multiple ways. Let’s discuss each method one by one.

Reverse Number in Java using While Loop

  1. Take a number as input (num).
  2. Extract the last digit from (num) using num%10 and concatenete it to (rev).
  3. Remove the last digit from (num) using num/10.
  4. Repeat step 2 and 3 till last digit of (num).

reverse of the number

Let’s see its implementation in Java.


Reverse Number in Java Without using Another Variable

In this method instead of concatenating the last digit to rev, we output it. In this way, the digits from the back get printed and in the last we get reverse of the number as final output.


The concept of reversing a number in java comes handy in checking palindrome numbers. If you have any doubts or suggestions then please comment below.

This Post Has One Comment

  1. Smruti Sandhya Singh

    Plzzz give all the questions answer and programs of icse 10

Leave a Reply

16 − 7 =