In this tutorial, we are going to write a Java program to check whether a given number is palindrome or not in java programming with practical program code and step-by-step full complete explanation.

Java program to check palindrome number


Java program to check palindrome number.

 
import java.util.Scanner;

public class JavaApplication2{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
         
        int r, p = 0;  // r is remainder, p is palindrome
        
        // Enter number
        System.out.print("Enter number = ");
        int number = scanner.nextInt();
        
        int temp = number;
        while(temp > 0){
            r = temp % 10;
            p = (p*10)+r;
            temp = temp/10;
        }
        if(number == p)
            System.out.println(number +" is Palindrome");
        else
            System.out.println(number +" is not Palindrome");
    }
}


Output

 
Enter number = 4554
4554 is Palindrome