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