Java Program to Check Palindrome Number

A palindrome number is a number that remains the same when its digits are reversed. For example, 121, 1331, and 12321 are palindrome numbers.

๐Ÿง  What is a Palindrome?

Palindrome means the number reads the same forward and backward.

  • 121 → Reversed: 121 ✅
  • 123 → Reversed: 321 ❌

๐Ÿ› ️ Logic to Check Palindrome Number

  1. Take the input number.
  2. Reverse the number using a loop.
  3. Compare the reversed number with the original.
  4. If both are the same, it’s a palindrome.

๐Ÿ“Œ Java Code


public class PalindromeNumber {
    public static void main(String[] args) {
        int number = 121;
        int original = number;
        int reversed = 0;

        while (number != 0) {
            int digit = number % 10;
            reversed = reversed * 10 + digit;
            number /= 10;
        }

        if (original == reversed) {
            System.out.println(original + " is a Palindrome number.");
        } else {
            System.out.println(original + " is not a Palindrome number.");
        }
    }
}
  

✅ Output

121 is a Palindrome number.

๐Ÿงช Try With Other Numbers

Test with: 12321, 1331, 123

๐Ÿ“š Conclusion

This is a basic yet common question in Java interviews. Mastering it will help you understand number manipulation and logic building in Java.