我不明白为什么我没有得到我的输出回文。我怀疑它存在的问题在内循环,但我会很感激任何输入。项目欧拉回文产品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