Write a program in java to accept a number and check whether the number is palindromic number or not
Answers
Answered by
4
Answer:
import java.util.Scanner;
public class Project2_Question4
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int a = sc.nextInt();
int b=0, c;
int fin = a;
while(a>0)//The number has to be positive
{
c=a%10;
b=(b*10)+c;
a=a/10;
}
if(fin==b)//If the first digit is equal to last digit
System.out.println("The given number is a palindrome.");
else
System.out.println("The given number is not a palindrome.");
}
}
Explanation:
Similar questions