Java Program To Check If the given Number Is Palindrome or Not
In this tutorial, we will see a Java program to check if the given Number is palindrome or not.
Java Program To Check If the given Number Is Palindrome or Not
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* A Java program to check if the given number is a palindrome or not.
* @author coderolls.com
*/
public class PalindromeNumber {
public static void main(String[] args) {
int num = 125521;
checkIfPalindrome(num);
}
private static void checkIfPalindrome(int num) {
int numCopy = num;
int reversedNumber = 0;
int reminder;
while(numCopy != 0){
reminder = numCopy % 10;
reversedNumber = reversedNumber *10 + reminder;
numCopy /=10;
}
if (reversedNumber == num) {
System.out.println("The Number '" + num + "' is a Palindrome Number.");
} else {
System.out.println("The Number '" + num + "' is not a Palindrome Number.");
}
}
}
Output
1
The Number '125521' is a Palindrome Number.
Join Newsletter
Get the latest tutorials right in your inbox. We never spam!