write a program to check and display whether a given no is a palindrome number or not ( a palindrome number is one which is equal to its reverse example -141)
Answers
Answer:
import java.util.Scanner;
public class Palindrome
{
public static void main(String[] args)
{
int num , reversedInteger = 0, remainder, originalInteger;
Scanner sc=new Scanner(System.in);
System.out.print("ENTER A NUMBER: ");
num=sc.nextInt();
originalInteger = num;
//WE ARE FINDING THE FIRST AND THE LAST DIGITS IN THIS while loop
while( num != 0 )
{
remainder = num % 10;
reversedInteger = reversedInteger * 10 + remainder;
num /= 10;
}
//Checking whether the first and the last digit is the same and giving appropriate results
if (originalInteger == reversedInteger)
System.out.println(originalInteger + " is a palindrome.");
else
System.out.println(originalInteger + " is not a palindrome.");
}
}
Explanation: