-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathProblem_4.java
More file actions
37 lines (28 loc) · 905 Bytes
/
Problem_4.java
File metadata and controls
37 lines (28 loc) · 905 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
34
35
36
37
/*
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.
*/
class Problem_4 {
public static void main(String[] args) {
int maxProd = 0;
for (int i = 999; i > 99; i--)
{
for (int j = i; j > 99; j--)
{
int prod = i * j;
if (prod < maxProd)
break;
int num = prod;
int rev = 0;
while (num != 0)
{
rev = rev * 10 + num % 10;
num /= 10;
}
if (prod == rev && prod > maxProd)
maxProd = prod;
}
}
System.out.println(maxProd);
}
}