what is palindrome number in java

1 year ago 27
Nature

A palindrome number is a number that remains the same even after reversing its digits. For example, 545, 151, 34543, 343, 171, 48984 are palindrome numbers. To check if a number is a palindrome in Java, we can reverse the number and compare it with the original number. Here is an example code to check if a number is a palindrome in Java:

import java.util.Scanner;

public class PalindromeNumber {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter a number: ");
        int num = input.nextInt();
        int reversedNum = 0, remainder, originalNum;
        originalNum = num;
        while (num != 0) {
            remainder = num % 10;
            reversedNum = reversedNum * 10 + remainder;
            num /= 10;
        }
        if (originalNum == reversedNum) {
            System.out.println(originalNum + " is a palindrome number.");
        } else {
            System.out.println(originalNum + " is not a palindrome number.");
        }
    }
}

This program takes an integer input from the user and checks if it is a palindrome number or not.