-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblemFour
38 lines (36 loc) · 1.04 KB
/
ProblemFour
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
/**
* Gabriel Menescal
*
* Problem 4:
*
* A palindromic number reads the same both ways. The largest palindrome made from the product
* of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product
* of two 3-digit numbers.
*/
public class ProblemFour {
public static void main(String[] args) {
findPalindromicNum();
}
public static void findPalindromicNum() {
int num;
int palindrome = 0;
String number;
for (int i = 999; i > 0; i--) {
for (int j = i; j > 0; j--) {
num = i * j;
number = "" + num;
String reverse = "";
for (int k = number.length() - 1; k >= 0; k--) {
reverse += number.charAt(k);
}
if (number.equals(reverse)) {
if (num > palindrome) {
palindrome = num;
}
}
}
}
System.out.println(palindrome);
}
}
// OUTPUT: 906609