Write a program to Reverse a number.

public class ReverseNumber {

	public static void main(String[] args) {

		int number = 136892;
		int reversedNum = 0;

		int temp = 0;
		int inputNum = number;

		while (inputNum > 0) {

			temp = inputNum % 10;

			reversedNum = reversedNum * 10 + temp;

			inputNum = inputNum / 10;

		}

		System.out.println("Reverse of " + number + " is: " + reversedNum);
	}
}


Output
Reverse of 136892 is: 298631










Related Examples


Write a program to check if an input String is Palindrome or not?
Calculate the factorial of a given number using Java?
How to reverse a number in Java?
Write a program to convert from decimal to binary?
Producer Consumer Example in Thread
Write a program to reverse a String?








Receive Latest Java Examples in Your Email: