Palindrome Program in Java - How to Check Palindrome Program Series



Palindrome Program in Java :

  • A palindrome number is a number that is same after reverse. For example 34543, 343, 545, 151, 171, 48984 are the palindrome numbers. It can also be a string like MADAM etc.

Sample Code

import java.util.Scanner;

public class palindrome 
{
  public static void main(String[] args) 
  {
    int n, r, sum = 0, temp;
    System.out.println("Enter the Number: ");
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    temp = n;
    while (n > 0) 
    {
      r = n % 10;
      sum = (sum * 10) + r;
      n = n / 10;
    }
    if (temp == sum)
      System.out.println("Number is Palindrome.");
    else
      System.out.println("Number is not Palindrome");
  }
}

Output

Enter the Number: 12321
Number is Palindrome.
Enter the Number: 12352
Number is not Palindrome

Related Searches to Palindrome Program in Java - How to Check Palindrome Program