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

• 08-05-2012, 04:02 AM
AcousticBruce
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.

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;         } }```
• 08-05-2012, 06:25 PM
.paul.
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
• 08-05-2012, 09:26 PM
AcousticBruce
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.