我不明白爲什麼我沒有得到我的輸出迴文。我懷疑它存在的問題在內循環,但我會很感激任何輸入。項目歐拉回文產品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 class projecteuler4 {
public static boolean isPalindrome(String palindromeCandidate) {
StringBuilder sb1 = new StringBuilder(palindromeCandidate);
if (sb1.equals(sb1.reverse()))
return true;
else
return false;
}
public static void main(String[] args) {
String answer;
for (int i = 100; i <= 999; i++) {
for (int j = i; j <= 999; j++) {
int ans = i * j;
answer = Integer.toString(ans);
if(isPalindrome(answer)) {
System.out.println(answer);
}
else
continue;
}
}
}
+1:從最大的數字開始,而不是從最小的數字開始。 ;) – 2012-03-14 14:02:26