Write a Java program to reverse an Integer

Below program illustrates how to reverse an Integer in Java:

public class ReverseInteger {
 
	public static void main(String[] args) {
		int num = 12345;
		int result = reverse(num);
		System.out.println(result);
 
	}
 
	private static int reverse(int n) {
		int result = 0;
		while (n > 0) {
			int rem = n % 10;
			n = n / 10;
			result = (result * 10) + rem;
		}
		return result;
	}
 
}

Author: Mahesh

Technical Lead with 10 plus years of experience in developing web applications using Java/J2EE and web technologies. Strong in design and integration problem solving skills. Ability to learn, unlearn and relearn with strong written and verbal communications.