Palindrome Number Example Java Program

Definition

A palindromic number or numeral palindrome is a number that remains the same when its digits are reversed. Like 16461, for example, it is "symmetrical". Although palindromic numbers are most often considered in the decimal system, the concept of palindromicity can be applied to the natural numbers in any numeral system.

Palindrome Number Example Program

import java.util.Scanner;

class PalindromeNumber{ 
    public static void main(String args[]){ 
		System.out.print("Enter the Number: ");
		Scanner in= new Scanner(System.in);
		int num =in.nextInt();
		int n = num;
		int rev=0,rmd; 
		while(num > 0) { 
			rmd = num % 10; 
			rev = rev * 10 + rmd; 
			num = num / 10; 
		} 
		if(rev == n){
			System.out.println("The given number is a palindrome!");
		}
		else {
			System.out.println("The given number is not a palindrome"); 
		}
    } 
}

Sample Output

Output is:
Enter the Number: 34543
The given number is a palindrome!