Java Program To Check If The Number Is Palindrome Or Not
A palindrome number is a type of number that reads the same backwards as forward. In other words, if you reverse the digits of a palindrome number, it will still remain the same. Palindrome numbers are symmetrical, and this property holds true regardless of the number of digits the number has. For
Example :
121 is a palindrome number because its reverse is also 121.
12321 is a palindrome number because its reverse is also 12321.
Program :
class HelloWorld {
public static boolean isPalindrome(int number) {
if (number < 0) {
return false;
}
int orginalNumber = number;
int sum = 0;
while (number > 0) {
int lastNumber = number % 10;
sum = (sum * 10) + lastNumber;
number = number / 10;
}
return sum == orginalNumber;
}
public static void main(String[] args) {
System.out.println(isPalindrome(121));
}
}
0 Comments