Java Program to Check a Number is Palindrome or Not

In this example, we are giving a program to check whether a number is palindrome or not.


To check a number is palindrome or not:

  1. # To check a number is palindrome or not
  2. public class Palindrome {
  3. public static void main(String[] args) {
  4. int num = 737, reversedInteger = 0, remainder, originalInteger;
  5. originalInteger = num;
  6. while( num != 0) {
  7. remainder = num % 10;
  8. reversedInteger = reversedInteger * 10 + remainder;
  9. num /= 10;
  10. }
  11. if(originalInteger == reversedInteger)
  12. System.out.println(originalInteger + " is a palindrome.");
  13. else
  14. System.out.println(originalInteger + " is not a palindrome.");
  15. }
  16. }

Output:

737 is a palindrome number.