Project Euler Problem 4 Java Solution - Largest Palindrome Product

Students of programming should enhance skills in logic. This can be done by practicing increasing difficulty of logical programming challenges. We can find such problems in Project Euler. We provide below solution to Euler Project problems so we can compare our solutions. In here we show a possible code that derives the answer for Euler Problem #4 with title - Largest Palindrome Product.

Project Euler Problem #4 - Largest Palindrome Product

Problem number four in the Euler Project involves numerical palindrome, below is how it is stated.
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.
A simple implementation to achieve the solution is given below.
/**
 * A simple implementation to solve Euler Problem #4 - Largest Palindrome Product.
 */
public class EulerProblemSolution {
    public static void main(String[] args) {
        int maxNumber = 999;
        long maxAnswer = 0;
        for(int i = maxNumber; i >=0; i--) {
            for(int j = maxNumber; j >= 0; j--) {
                long possibleAnswer = i * j;
                if(possibleAnswer == reverse(possibleAnswer) && possibleAnswer > maxAnswer) {
                    maxAnswer = possibleAnswer;
                }
            }
        }
        System.out.println(maxAnswer);
    }
    public static long reverse(long n) {
        long reverse = 0;
        while (n != 0) {
            long lastDigit = n % 10;
            reverse = reverse * 10 + lastDigit;
            n /= 10;
        }
        return reverse;
    }
}

This program outputs the answer to the problem which is:

906609