You are here: Home / Topics / Program to check palindrome number in Java

Program to check palindrome number in Java

Filed under: Java on 2023-08-18 06:57:33

// check given number is palindrom or not

public class PalindromeNumber {

   public static void main(String[] args) {
       int n = 1215;
       int sum = 0;
       int m = n;

       while (n > 0) {
           //int sum=0;
           int r = n % 10;
           sum = sum * 10 + r;
           n = n / 10;

       }
       if (m == sum) {
           System.out.println("palindrome");
       } else {
           System.out.println("not palindrome");
       }
   }
}


Output:

not palindrome

About Author:
Y
Yatendra Sir     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.