We need to write a java program to reverse a number and output it.

Example:

A number in java can be reversed in multiple ways. Let’s see each of them.

Steps to Reverse a Number

  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

Reverse Number in Java using While Loop

Output

Reverse Number in Java Without using Another Variable

Output

If you have any doubts, comment below.

Leave a Reply

Close Menu