Java Program to Check Whether a Number is Palindrome or Not

  • How to check whether a number is palindrome or not using loop.

An integer is called palindrome number, If the number remains same after reversing the sequence of it's digits. To check whether a number is palindrome number or not, we will create a copy of input number and reverse it's digits. If reversed number is same as input number then it is a palindrome number other not a palindrome number.

Algorithm to check whether a number is palindrome or not
  1. Take a number as input from user and store it in an integer variable(Let's call it num).
  2. Reverse the digits of num, and store it in another integer variable(Let's call it reverse).
  3. Compare num and reverse.
  4. If both are equal then num is palindrome number otherwise not a palindrome number.

Java program to check for palindrome numbers


import java.util.*;

public class PalindromeNumberCheck {
    public static void main(String args[]) {
        int num, temp, reverse = 0, rightDigit;

        Scanner in = new Scanner(;
        System.out.println("Enter a number");
        num = in.nextInt();
        temp = num;
        /*reverse num and store it in reverse */
        while(temp != 0){
            rightDigit = temp % 10;
            reverse = reverse*10 + rightDigit;
            temp = temp/10;
        if(reverse == num)
            System.out.print(num + " is Palindrome number");
        } else {
            System.out.print(num + " is not a Palindrome number");
Enter a number
1234321 is Palindrome number
Enter a number
72537625 is not a Palindrome number