-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproblem4.java
48 lines (39 loc) · 1.1 KB
/
problem4.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class problem4 {
public static void main(String args[]){
System.out.println(palindrome());
}
private static int palindrome() {
int init = 999;
int result = 0;
boolean found = false;
// Find the lagest number which have 3 digits and is multiples of 11
while (init > 100) {
if (init % 11 == 0) {
break;
} else {
init--;
}
}
while (init > 100) {
for (int i = 999; i > 100; i--) {
int check = init * i;
if (isPalindrome(check)) {
if (check > result) {
result = check;
}
break;
}
}
init -= 11;
}
return result;
}
private static boolean isPalindrome(int input) {
String str = String.valueOf(input);
String revertStr = "";
for(int i = str.length() - 1; i >= 0; i--) {
revertStr += str.charAt(i);
}
return str.equals(revertStr);
}
}