A palindrome number is a number that is same after reverse. For example 545, 151, 34543, 343, 171, 48984
package javabox;
class PalindromeExample{
public static void main(String args[]){
int r,sum=0,temp;
int n=454; //Number to be checked for palindrome
temp=n;
while(n>0){
r=n%10; //getting remainder
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
System.out.println("Palindrome number ");
else
System.out.println("Not palindrome");
}
}
Output -
Palindrome number
No comments:
Post a Comment