-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem6.java
More file actions
executable file
·45 lines (37 loc) · 1.04 KB
/
Problem6.java
File metadata and controls
executable file
·45 lines (37 loc) · 1.04 KB
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
/**
* Problem6
* 1 = 9 ( 3x 3)
* 2 = 9009 ( 99x 91)
* 3 = 906609 ( 993x 913)
* 4 = 99000099 ( 9999x 9901)
* 5 = 9966006699 ( 99979x 99681)
* 6 = 999000000999 ( 999999x 999001)
* 7 = 99956644665999 ( 9998017x 9997647)
* 8 = 9999000000009999 (99999999x99990001)
*/
public class Problem6 {
public static void main(String[] args) {
int ul = 999;
int ll = 100;
long ans = 0;
boolean found = false;
for (int i=ul; i>ll; i--) {
for(int j=i; j>ll;j--){
long mul = i*j;
if (isPalindrome(mul) && mul>ans){
ans = mul;
}
}
}
System.out.println(ans);
}
private static boolean isPalindrome(long val) {
long temp = val;
long reverse = 0;
while(temp>0){
reverse = reverse*10 + temp%10;
temp/=10;
}
return reverse == val;
}
}