input a number and check whether it is palindrome or not. using digit seperation.
Answers
Answered by
1
Palindrome number : If the numbers remains same even if we reverse its digits. Eg: 121, 131, 111, .....
Program for palindrome number:
import java.util.*;
class Basic
{
public static void main(String[] args)
{
int a,b=0,c,d;
Scanner demo = new Scanner(System.in);
System.out.println("Enter a number: ");
a = demo.nextInt();
d = a;
while(a > 0)
{
c = a%10;
b = (b * 10) + c;
a = a/10;
}
if(d == b)
{
System.out.println ("Entered number is a palindrome");
}
else
{
System.out.println ("Entered number is not a palindrome");
}
}
}
Output:
Enter a number: 153
Entered number is not a palindrome.
Enter a number: 121
Entered number is a palindrome
Similar questions