-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp004.java
26 lines (24 loc) · 867 Bytes
/
p004.java
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
public class p004{
public static void main(String arg[]){
int max = 1;
for (int i = 100; i < 999; i++) {
for (int j = i; j < 999; j++) {
int n = i * j;
int len = (int) Math.floor(Math.log10(n));
boolean ispalindrome = true;
for (int k = 0; k < 3; k++) {
int digitatk = (int) ((n % Math.pow(10, k + 1) - n% Math.pow(10, k)) / Math.pow(10, k));
int l = len - k;
int digitatl = (int) ((n % Math.pow(10, l + 1) - n% Math.pow(10, l)) / Math.pow(10, l));
if (digitatl != digitatk) {
ispalindrome = false;
}
}
if (ispalindrome && n > max) {
max = n;
}
}
}
System.out.println(max);
}
}