Java Program to check Palindrome

Ads
 

Java Program to check Palindrome

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

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

Ads

Ads