Java Programming Challenge Code Not Working [closed]

Your logic goes wrong when you are checking for divisibility in the following loop:

 for(int j = 99; j >= 1; j--){
            if(numbers.get(i).intValue() % j == 0){
                product = true;
                break;
            }

Here you are just checking if the palindrome is divisible by a number between 1-99 but you are not worried about the other factor of the palindrome.

Example:
Let the palindrome be 2222.
When checking for its divisibility (inside ‘j’ loop), it is divisible by 22 and hence you are including it in the list, where as the other factor is 101 which is not a 2-digit/1-digit number.
You have to eliminate all such cases.

So instead of following this algorithm, it is better if you follow the algorithm in a reverse way as mentioned by few users above.

Leave a Comment