Results 1 to 3 of 3
 08052012, 04:02 AM #1Senior Member
 Join Date
 Dec 2010
 Location
 Indiana
 Posts
 202
 Rep Power
 10
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 3digit 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; } }

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
 08052012, 09:26 PM #3Senior Member
 Join Date
 Dec 2010
 Location
 Indiana
 Posts
 202
 Rep Power
 10
Similar Threads

JOptionPane.showInputDialog with only 1 correct answer
By Gladiat0r in forum New To JavaReplies: 1Last Post: 03182012, 09:42 PM 
trivial string formatting problem that I just cannot find the answer to
By rippon in forum New To JavaReplies: 3Last Post: 02272011, 12:03 AM 
couldnt find the answer..
By amaliutz in forum New To JavaReplies: 12Last Post: 02032011, 04:08 PM 
why my coding cannot give the correct answer?
By qema in forum New To JavaReplies: 5Last Post: 03032009, 05:52 PM 
guss which is correct answer
By abhinav_jain09 in forum Java AppletsReplies: 4Last Post: 09192008, 02:39 AM
Bookmarks