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_imp_func{
public void f1(int n)
{
int r,s=0,t;
t=n;
while(n!=0)
{
r=n%10;
s=(s*10)+r;
n=n/10;
}
if(t==s)
{
System.out.println("Entered number is Palindrome");
}
else
System.out.println("Entered number is not Palindrome");
}
public static void main(String args[])
{
int a;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number to check its a palindrome or not:");
a=sc.nextInt();
Palin_imp_func obj=new Palin_imp_func();
obj.f1(a);
}
Output:
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