Java Program to check a number is palindrome or not


In this program, You will learn how to check a number is palindrome or not in Java.


Some list of palindrome numbers is : 11, 121, 111, 81218


Example: How to check a number is palindrome or not in Java

Run it Now
import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        int n, num, r, rev = 0;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a Number :");
        n = sc.nextInt();
        num = n;
        while (n > 0) {
            r = n % 10;
            rev = rev * 10 + r;
            n = n / 10;
        }

        if (num == rev) {
            System.out.println("\nNumber is Palindrome :" + num);
        } else {
            System.out.println("\nNumber is Not Palindrome :" + num);
        }

    }
}

Output:

Enter a Number :121
Number is Palindrome :121