-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsPalindrome.java
More file actions
48 lines (33 loc) · 863 Bytes
/
Copy pathIsPalindrome.java
File metadata and controls
48 lines (33 loc) · 863 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package org.example;
public class IsPalindrome {
public static boolean isPalindrome(int x) {
if (x < 0) {
return false;
}
int div = 1;
int t = x / 10;
while (t != 0) {
div = div * 10;
t = t / 10;
}
System.out.println("div = " + div);
int n = x;
while (n != 0) {
int left = n / div;
int right = n % 10;
System.out.print("left = " + left);
System.out.println(", right = " + right);
if (left != right) {
return false;
}
n = n % div / 10;
// bug
div = div / 100;
}
return true;
}
public static void main(String[] args) {
int x = 1000021;
IsPalindrome.isPalindrome(x);
}
}