public class ReverseNumber
{
public static void main(String args[])
{
int num = 654321, reverse = 0;
while (num != 0)
{
int remainder = num % 10;
reverse = reverse * 10 + remainder;
num = num / 10;
}
System.out.println("The reverse of the given number is:" + reverse);
}
}
Compile:
javac ReverseNumber.java
java ReverseNumber
Output:
The reverse of the given number is : 123456