# Thread: Prob 4 ProjectEuler. It does find the correct answer, but I also want the multiples.

1. Senior Member
Join Date
Dec 2010
Location
Indiana
Posts
202
Rep Power
3

## Prob 4 ProjectEuler. It does find the correct answer, but I also want the multiples.

I have probably been looking at this code too long and now I am confused. This is Question 4 with ProjectEuler.

I am trying to figure out why minFinal and maxFinal are wrong. The palindromic is correct but I was curious as to what the products were.

Also I do not mind and would very much appreciate if you critique my code and let me know of some annoyances that I can fix.

Java Code:
```/**
*Find the largest palindrome made from the product of two 3-digit numbers.
*/

public class Prob4_LargestPal {

public static void main(String[] args) {
PalFinder pf = new PalFinder();
pf.findLargestPal(100, 999);
}
}

class PalFinder {

String testString;
String LargestPal;

void findLargestPal(int min, int max) {

int minFinal = 0, maxFinal = 0;
int testNum = 0, highest = 0;

for(int i = max; i >= min; i--) {
for(int ii = max; ii >= min; ii--) {
testNum = (ii*i);
if(isThisPalindromic(testNum)) {
if(testNum > highest) {
highest = testNum;
minFinal = min;
maxFinal = max;
}
}
}
}
System.out.printf("The largest palindromic # is \n%s with the product of \n%s and %s.", highest, minFinal, maxFinal);
}

// Method for determining if a number is palindromic with boolean
boolean isThisPalindromic(int test) {

testString = Integer.toString(test);

for(int i = 0; i < (testString.length()/2);i++) {
if(testString.charAt(i) != testString.charAt(testString.length() - i - 1)) {
return false;
}
}
return true;
}
}```

2. Member
Join Date
Jun 2012
Posts
73
Blog Entries
1
Rep Power
0

## Re: Prob 4 ProjectEuler. It does find the correct answer, but I also want the multipl

minFinal = min;
maxFinal = max;

minFinal + maxFinal will always be min + max.
you need to use i + ii

3. Senior Member
Join Date
Dec 2010
Location
Indiana
Posts
202
Rep Power
3

## Re: Prob 4 ProjectEuler. It does find the correct answer, but I also want the multipl

LOL. I knew I was coding too long. Sheesh. Thanks.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•