Skip to content

Commit 5ecc71a

Browse files
authored
added solution of Palindrome Number in Java (Tahanima#49)
1 parent 5da7b8d commit 5ecc71a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public boolean isPalindrome(int x) {
3+
if (x < 0)
4+
return false;
5+
6+
int reversedInteger = 0, lastDigit, temp;
7+
temp = x; // storing the original number to a temporary variable
8+
// Reversing the number
9+
while (temp != 0) {
10+
lastDigit = temp % 10;
11+
reversedInteger = reversedInteger * 10 + lastDigit;
12+
temp = temp / 10;
13+
}
14+
// checking if palindrome or not using condition
15+
if (reversedInteger == x)
16+
return true;
17+
else
18+
return false;
19+
}
20+
}

0 commit comments

Comments
 (0)