Reverse the number - Java Program

Q. Write a java program to reverse the number.

Answer:

Reverse.java

class Reverse
{
        public static void main(String[] args)
        {
                int number = 12345;
                int reverse = 0;
                System.out.println("Given number is: "+number);
                while (number != 0)
                {
                        reverse = reverse * 10;
                        reverse =reverse + number%10;
                        number = number/10;
                }
                System.out.println("Reverse number is: "+reverse);
        }
}


Output:

reverse no