Thursday 1 September 2016

Check Palindrome of Number

Palindrome Program in Java


Palindrome number in java: A palindrome number is a number that is same after reverse. For example 545, 151, 34543, 343, 171, 48984 are the palindrome numbers.


  1. class PalindromeExample{  
  2.  public static void main(String args[]){  
  3.   int r,sum=0,temp;    
  4.   int n=454;//It is the number variable to be checked for palindrome  
  5.   
  6.   temp=n;    
  7.   while(n>0){    
  8.    r=n%10;  //getting remainder  
  9.    sum=(sum*10)+r;    
  10.    n=n/10;    
  11.   }    
  12.   if(temp==sum)    
  13.    System.out.println("palindrome number ");    
  14.   else    
  15.    System.out.println("not palindrome");    
  16. }  
  17. }  
Output:
palindrome  number




No comments:

Post a Comment