- Home
- Java Number Programs (ISC Classes 11 / 12)
Palindrome Number in Java
Java Number Programs (ISC Classes 11 / 12)
Palindrome Number in Java: Write a program to accept a number from the user and check whether it is a Palindrome number or not. A number is a Palindrome which when reads in reverse order is same as in the right order.
Sample Input: 242
Sample Output: A Palindrome number
Sample Input: 467
Sample Output: Not a Palindrome number
Answer
import java.util.Scanner;
public class KboatPalindromeNumber
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the number: ");
int num = in.nextInt();
int copyNum = num;
int revNum = 0;
while(copyNum != 0) {
int digit = copyNum % 10;
copyNum /= 10;
revNum = revNum * 10 + digit;
}
if (revNum == num)
System.out.println("A Palindrome number");
else
System.out.println("Not a Palindrome number");
}
}