Project Euler #4 - Largest Palindrome Product in Java I am seeing that this is actually not in accord with the difficulty level said there. Firstly I cannot list all possible improvements it could have.

/*
 * 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 static int get4() {
    int max = 1;
    for (int i = 100; i &lt; 999; i++) {
        for (int j = i; j &lt; 999; j++) {
            int n = i * j;
            int len = (int) Math.floor(Math.log10(n));
            boolean ispalindrome = true;
            for (int k = 0; k &lt; 3; k++) {// 100^2=10^4,999^2=998001. 5-6
                                            // digits middle atmax 3
                int digitatk = (int) ((n % Math.pow(10, k + 1) - n
                        % Math.pow(10, k)) / Math.pow(10, k));
                // eg. digit at 3 of 12345 =
                // (12345%10^4-12345%10^3)/10^3=(2345-345)/10^3=2000/10^3=2
                int l = len - k;
                int digitatl = (int) ((n % Math.pow(10, l + 1) - n
                        % Math.pow(10, l)) / Math.pow(10, l));
                if (digitatl != digitatk) {
                    ispalindrome = false;
                }
            }
            if (ispalindrome &amp;&amp; n &gt; max) {
                max = n;
            }
        }
    }
    return max;
}


Output:




Answer is 906609
Time taken 2.82342934 seconds



Current problems (not exhaustive):


Time
\${\mathcal O}(n^2)\$ where \$n=999\$ for looping only.
Length-checking method
Checking palindrome
Digit-finding method
Algorithm
Your time and complexity problems are probably the more serious ones. Your code starts small (at 100), and then works up to 1000. This is not the most efficient way of brute-forcing the problem. A better solution would be to start at 999 and work back to 100, but limit it when the result becomes impossible.... let me explain:
    int max = Integer.MIN_VALUE;
    for (int i = 999; i &gt; 100 &amp;&amp; i * 999 &gt; max; i--) {
        for (int j = 999; j &gt; i; j--) {
            ....


start high (999 x 999)
Work backwards from there where the second number is larger than the first
track your maximum
terminate the loops if the current i (or smaller) values will never beat the maximum.

Using the above logic, you will eliminate a huge number of loops.
Length check &amp; Finding digit
The Log function is a good check for the length of the value, it's fine. On the other hand, it may not be necessary at all... same applies to the &quot;finding digit&quot;
Palindrome
I like the following method for identifying palindromic numbers:
private static final int reverse(int value) {
    int result = 0;
    while (value != 0) {
        result *= 10;
        result += value % 10;
        value /= 10;
    }
    return result;
}

Using that function, your palindrome check simply becomes:
boolean ispalindrome = n == reverse(n);