/** * Find the largest palindrome made from the product of two 3-digit numbers. */ public long solveProblem4() { long largestPalindrome = 0; for (int a = 100; a <= 999; a++) { for (int b = 100; b <= 999; b++) { long possiblePalindrome = a * b; if (isPalindrome(possiblePalindrome) && possiblePalindrome > largestPalindrome) { largestPalindrome = possiblePalindrome; } } } return largestPalindrome; } /** * Is this number a palindrome? */ public static boolean isPalindrome(long number) { String string = String.valueOf(number); for (int i = 0; i < string.length() - 1; i++) { if (string.charAt(i) != string.charAt(string.length() - 1 - i)) { return false; } } return true; }