forked from nayuki/Project-Euler-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp004.java
More file actions
33 lines (27 loc) · 808 Bytes
/
p004.java
File metadata and controls
33 lines (27 loc) · 808 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
/*
* Solution to Project Euler problem 4
* Copyright (c) Project Nayuki. All rights reserved.
*
* https://www.nayuki.io/page/project-euler-solutions
* https://github.com/nayuki/Project-Euler-solutions
*/
public final class p004 implements EulerSolution {
public static void main(String[] args) {
System.out.println(new p004().run());
}
/*
* Computers are fast, so we can implement this solution directly without any clever math.
* Note that the maximum product is 999 * 999, which fits in a Java int type.
*/
public String run() {
int maxPalin = -1;
for (int i = 100; i < 1000; i++) {
for (int j = 100; j < 1000; j++) {
int prod = i * j;
if (Library.isPalindrome(prod) && prod > maxPalin)
maxPalin = prod;
}
}
return Integer.toString(maxPalin);
}
}