Palindrome number – a number is a Palindrome which when read in reverse
order is same as read in the right order. Example: 121, 11, 15451, etc.
Program:
import java.util.*;class Palin_do_while
{
public static void main(String args[])
{
int n,s=0,r,t;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number to check its a palindrome or not:");
n=sc.nextInt();
t=n;
do
{
r=n%10;
s=(s*10)+r;
n=n/10;
}
while(n!=0);
if(t==s)
{
System.out.println("Entered number is Palindrome");
}
else
System.out.println("Entered number is not Palindrome");
}
}
Enter the number to check its a palindrome or not:
121
121
Entered number is Palindrome
Enter the number to check its a palindrome or not:
12211
Entered number is not Palindrome12211