-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem4.java
More file actions
49 lines (38 loc) · 970 Bytes
/
Copy pathproblem4.java
File metadata and controls
49 lines (38 loc) · 970 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
38
39
40
41
42
43
44
45
46
47
48
49
public class problem4 {
/**
* 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 static void main(String[] args) {
// TODO Auto-generated method stub
int product = 1,max = 0;
String intToString = "";
boolean bool = true;
for(int i = 100;i<999;i++){
for(int j = i; j<999;j++){
product = i * j;
intToString = Integer.toString(product);
bool = palindrome(intToString);
if(bool){
if( product > max)
max = product;
}
}
}
System.out.print(max);
}
public static boolean palindrome(String palindrome){
int start = 0,end = palindrome.length() -1;
while(start < end){
if(palindrome.charAt(end) != palindrome.charAt(start)){
return false;
}
start++;
end--;
}
return true;
}
}