by Dinesh Thakur

The Java Example to check if a Number is a palindrome or not.  A Number is palindrome if it remains unchanged when it is reversed, for example "151" is a palindrome as its reverse is "151".

Algorithm for Palindrome Number:

 

step 1:Set s=0

step 2: Read num

step 3: Set b=num

step 4: Repeat through step-7until (num > 0)

step 5: r=num%10

step 6: s=(s*10)+r

step 7: num=num/10

step 8: If b equals to s then print" b is palindrome"

Else print" b is not a palindrome"

step 9: Exit

 

Here is the Java Example for Palindrome Number:

import java.util.Scanner;

class PalindromeNumber
{
                public static void main(String args[])
            {
                      int num,d,s,b;
                Scanner sl=new Scanner(System.in);
                System.out.print("Enter A Number : ");
                num=sl.nextInt();
                b=num;
                s=0;
                while(num!=0)
                      {
                         d=num%10;
                         s=(s*10)+d;
                         num=num/10;
                       }
                         if(s==b)
System.out.println(b+ " and "+ s + " are Same So it is Palindrome");
else
System.out.println(b+ " and " + s + " are Not Same So it is Not Palindrome");
           }
}

Palindrome Number in Java