Write a Java Program to find given number is Palindrome or Not

By | 21.01.2017

Write a Java Program to find given number is Palindrome or Not


A Palindrome number is a number that remains the same when its digits are reversed.

Like 12321, for example: we take 121 and reverse it, after revers it is same as original number.

 

SOURCE CODE ::

import java.util.Scanner;
class Palindrome 
{
public static void main(String[] args) 
{
        int a,no,b,temp=0;
        Scanner s=new Scanner(System.in);
        System.out.println("Enter any num: ");
        no=s.nextInt();
        b=no;
        while(no>0)
            {
            a=no%10;
            no=no/10;
            temp=temp*10+a;
        }
        if(temp==b)
        {
            System.out.println("Palindrome");
        }
        else
        {
            System.out.println("not Palindrome");
        }
}
}

 

OUTPUT ::

 

Enter any num: 
1221
Palindrome

 

5 3 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments