I was trying to solve project Euler problem 4 which is:
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.
Here is my solution , it's output is 997799 , however that's not the correct answer ,I wonder where is the problem:
package projecteuler;
public class Pro4 {
public static void main(String[] args) {
for(int i=999*999;i>=100*100;i--){
if(isPalindrome(i)==true){
System.out.println(i);
break;
}
}
}
static boolean isPalindrome(int x){
int[] bits = new int[7];
int index=1;
while(x>0){
bits[index]=x%10;
index++;
x/=10;
}
for(int i=1;i<=index/2;i++){
if(bits[i]!=bits[index-i]){
return false;
}
}
return true;
}
}
See Question&Answers more detail:os