Palindrome Number in Java
Program to check if a number is a palindrome (reads same forwards and backwards).
Last updated: 11 January 2026
Method 1: Reversing Number
Reverse the number and compare.
Main.javaRun in Compiler →
public class Palindrome {
public static void main(String[] args) {
int num = 121, reversedNum = 0, remainder;
int originalNum = num;
while (num != 0) {
remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num /= 10;
}
if (originalNum == reversedNum) {
System.out.println(originalNum + " is Palindrome.");
} else {
System.out.println(originalNum + " is not Palindrome.");
}
}
}Output:
121 is Palindrome.
Explanation
We reverse the integer and check if it equals the original number.
Frequently Asked Questions
Try This Program
Copy this code and run it in our free online Java compiler.
Open Java Compiler