Enter any integer as an input. After that we perform various operations like modulus and division to reverse the number and check whether the given integer is palindrome or not. Hence we generate the output accordingly.
Here is the source code of the Java Program to Reverse a Number & Check if it is a Palindrome. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Palindrome
public static void main(String args)
int n, m, a = 0,x;
Scanner s = new Scanner(System.in);
System.out.print("Enter any number:");
n = s.nextInt();
m = n;
while(n > 0)
x = n % 10;
a = a * 10 + x;
n = n / 10;
if(a == m)
System.out.println("Given number "+m+" is Palindrome");
System.out.println("Given number "+m+" is Not Palindrome");
$ javac Palindrome.java $ java Palindrome Enter any number:121 Given number 121 is Palindrome Enter any number:145 Given number 145 is Not Palindrome
Sanfoundry Global Education & Learning Series – 1000 Java Programs.