# Display the reverse of any number using Java

There we will learn how to find the reverse of any numbers. that number may have N numbers of digits.

For Example.
The actual number which is input by user is: 12678
the reverse number of that number is: 87621

## Algorithm

```Step 1: Import java.io.* package
Step 2: Create a class
Step 3: Define main method
Step 4: Input any number from user
Step 5: While ( a > 0 ) then Calc the Mod 10 and store in another variable
Step 6: Take another variable and multiple by 10 and add with Calculated mod value
Step 7: Divide the actual number by 10
Step 8: Repeat the 5, 6, 7 Steps until a > 0
Step 9: Display the reverse number
Step 10: Exit```

## Source Code

```java.io.*;

public static void main(String rags[]) {
try {
Console con = System.console();
int a,rev = 0,b = 0;

//input in float and int using console class
System.out.println("Enter Any Numbers to find the reverse of them");

while ( a > 0) { //Checking while a is not zero
b = a % 10;
rev = rev * 10 + b;
a = a / 10;
}

System.out.println("Reverse number is: " + rev);
} catch (Exception er) {
System.out.println(er);
}
}
}
```

## Output

```Enter Any Numbers to find the reverse of them
1285
Reverse number is: 5821
```