CodersZone logo

Palindrome Number

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

Algorithm

  1. Get the number to check for palindrome
  2. Hold the number in temporary variable
  3. Reverse the number
  4. Compare the temporary number with reversed number
  5. If both numbers are same, print "palindrome number"
  6. Else print "not palindrome number"

Code

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

Output

454 is a palindrome number
 
See the same program in C See the same program in Python