Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Beginners Java Program to check Palindrome

 
 

Share on Google+Share on Google+

Java Program to check Palindrome

Advertisement
In this section, you will learn about the palindrome number and how to determine any number is palindrome or not.

Java Program to check Palindrome

In this section, you will learn about palindrome in java and how to check any number that is palindrome or not. First of all what is palindrome number?, this is the number that the original number is same after reversing this. For example let us suppose that, the original number is 121 and by reversing this number we get the same number, then it is called palindrome number otherwise it is not.

Description of program : With the help of this program, we are going to check whether the number is palindrome or not. At first you have to defined a class name "palindrome". After that will ask the user to enter any number of type integer and then reverse that number. After reversing that number check whether that number is palindrome or not. We will check it in the if condition that the reverse number is equal to the original number otherwise else part get executed and prints "This is not palindrome".

import java.util.Scanner;
public class Palimdrome 
 {
   public static void main(String args[])
	{
		System.out.println("");
	    System.out.println("Enter the number you want to check ");
		int  number= new Scanner(System.in).nextInt();
	    int palimdrm=number;// sin copied to palimdrome
	    int reverse=0;
	    while(palimdrm!=0)
	    {
	    	int rem=palimdrm%10;
	    	reverse=reverse *10 + rem;
	    	palimdrm=palimdrm/10;
	    	
	    }
	     if(number==reverse)
	     {
	    	 System.out.println("");
	    	 System.out.println("This is palindrome number");
	     }
	     else
	     {
	    	 System.out.println("This is not palindrome number");
	     }
	}
}

Output from the program :

Download Source Code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 25, 2013

Related Tutorials

Discuss: Java Program to check Palindrome  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com