59. JAVA Program To check a Number is Palindrome number or Not.
How does this program work?
- This program is used to check given string is palindrome or not using JAVA.
- Palindrome String is a string which means if it remains same even after reversing the given string.
- A string said to be a palindrome if original string is equal to the reverse of the given string otherwise it is not a palindrome.
Here is the code
// Palindrome or Not.
import java.util.Scanner;public class Number
{
public static void main(String args[])
{
int r,sum=0,temp,n;
System.out.println("Enter number :\n" );
Scanner obj=new Scanner(System.in);
n=obj.nextInt();
temp=n;
while(n>0)
{
//Getting remainder
r=n%10;sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
System.out.println(sum+" is a palindrome number ");
else
System.out.println(sum+ " is not a palindrome number");
}
}