-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathanswer.java
More file actions
32 lines (27 loc) · 776 Bytes
/
answer.java
File metadata and controls
32 lines (27 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class Solution {
public boolean isPalindrome(int x) {
int temp = x, digits = 1;
// If x is negative
if (x < 0)
return false;
// Find 1^digits
while (temp >= 10){
temp /= 10;
digits *= 10;
}
// While there are numbers left
while (x > 0){
if ((x % 10) != (x / digits))
return false;
// Removes a digit off each side
x = (x % digits) / 10;
// Removes 2 digits
digits /= 100;
}
return true;
}
}
//-----------------------------------------------------------------------------
public static void main(String[] args){
system.out.println(isPalindrome(1234321));
}