Showing posts with label Palindrom or not program in java. Show all posts
Showing posts with label Palindrom or not program in java. Show all posts

Saturday, 9 January 2016

JAVA Program to check whether a number is Palindrome

Palindrome number check USING JAVA

A program to accept a number from keyboard and check whether it is Palindrome.


//A small java program to check the given number is Palindrome or not.

import java.util.Scanner;

public class PalindromeExample {
  public static void main(String args[]){  
  int r,sum=0,temp;
  System.out.println("Enter a number to check whether it is Palindrome");
  Scanner in = new Scanner(System.in);  
  int n=in.nextInt();     //It is the number variable to be checked for palindrome
  int finalPrint = n;
  temp=n;    
  while(n>0){    
      r=n%10;  //getting remainder  
      sum=(sum*10)+r;    
      n=n/10;    
  }    
  if(temp==sum)    
      System.out.println(finalPrint +" is a palindrome number.");    
  else    
      System.out.println(finalPrint +" is not a palindrome number.");    
}  
}

Output:


Enter a number to check whether it is Palindrome
4554
4554 is a palindrome number.