Search Your Topic

config
Thursday, 18 May 2017 03:24

Palindrome Program in Java

Written by
Rate this item
(0 votes)

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.

Palindrome number algorithm

  • Get the number to check for palindrome
  • Hold the number in temporary variable
  • Reverse the number
  • Compare the temporary number with reversed number
  • If both numbers are same, print "palindrome number"
  • Else print "not palindrome number"

Let's see the palindrome program in java. In this java program, we will get a number variable and check whether number is palindrome or not.

 
  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
Read 262 times
Anish Sir

"I am delighted once again to pen the welcome note to the Tosh!Yas Technologies ."

 Call +91 74 88 34 7779  | Email : anishsingh@live.com

toshiyas.in

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.

Java Training

Facebook