Computer Applications

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

Java

Java Iterative Stmts

203 Likes

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");
    }
}

Variable Description Table

Program Explanation

Output

Answered By

90 Likes


Related Questions