Palindrome Number - A palindrome number is a number such that if we reverse it, it will not
change. For example some palindrome numbers examples are 181, 252,
12321, -484.
import java.util.*;
class Palindrome
{
public static void main(String args[])
{
int n,s=0,m,r;
Scanner sc =new Scanner(System.in);
System.out.println("Enter the number");
n=sc.nextInt();
m=n;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(m==s)
System.out.println("Palindrome");
else
System.out.println("Not Palindrome");
}
}
Output:
Enter the number:
181
Palindrome
import java.util.*;
class Palindrome
{
public static void main(String args[])
{
int n,s=0,m,r;
Scanner sc =new Scanner(System.in);
System.out.println("Enter the number");
n=sc.nextInt();
m=n;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(m==s)
System.out.println("Palindrome");
else
System.out.println("Not Palindrome");
}
}
Output:
Enter the number:
181
Palindrome