wap to check if a number is palindrome
Answers
•Declare two variables: one stores the given number, and the other stores the reversed number.
•Run the do-while loop until the number of digits in the reversed number are equal to the number of digits in the given number. ...
•Check if the reversed number is equal to the given number.
Question:-
Write a program to check if a number is palindrome or not.
Program:-
In Java.
import java.util.*;
class Palindrome
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
int n=sc.nextInt();
int x=n, s=0;
while(n!=0)
{
s=s*10+n%10;
n/=10;
}
if(s==x)
System.out.print("Palindrome.");
else
System.out.print("Not Palindrome.");
}
}
In python.
n=int(input("Enter a number: "))
x, s=n, 0
while n!=0:
s=s*10+n%10
n=n//10
if(s==x):
print("Palindrome.")
else:
print("Not Palindrome.")