Palindrome Number In Java

What is Palindrome ?

A palindromic number or numeral palindrome is a ‘symmetrical’ number like 16461, that remains   the same when its digits are reversed.The first palindromic numbers (in decimal) are:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55….. etc

Description of program :

With the help of this program, we are going to determine whether the given number is palindrome or not. To achieve the desired result, firstly we have to define a class named “PalindromeNumberExampleJAVA “. After that we will ask the user to enter any integer type number and then we will reverse it. After reversing the number we will check whether the given number is palindrome or not.

Here is the code of this program :::

/*
* Palindrome Number Example In JAVA This Java Palindrome Number Example
* shows to find given number is palindrome number or not.
*/

public class PalindromeNumberExampleJAVA {

public void main(String[] args) {

// array of numbers to be checked
int num[] = new int[] { 41, 151, 65, 78, 55, 69, 11, 85 };

// iterate through the numbers
for (int i = 0; i < num.length; i++) {

int palNumber = num[i];
int reversedNum = 0;
int temp = 0;

/*
* If the number is equal to it’s reversed number, then the
* given number is a palindrome number.
*/

// reverse the number
while (palNumber > 0) {
temp = palNumber % 10;
palNumber = palNumber / 10;
reversedNum = reversedNum * 10 + temp;
}
if (num[i] == reversedNum)
System.out.println(num[i] + ” is a palindrome number”);
else
System.out.println(num[i] + ” is not a palindrome number”);
}

}
}

/*
Output of Java Palindrome Number Example would be

41 is not a palindrome number
151 is a palindrome number
65 is not a palindrome number
78 is not a palindrome number
55 is a palindrome number
69 is not a palindrome number
11 is a palindrome number
85 is not a palindrome number
*/

Enjoy Code….