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.
Create a double loop for each three digit number. Test each as a palindrome and pick the largest number.
public class Euler4
{
public static void main(String[] args)
{
System.out.print(“Problem 4:\n”);
Euler4 e = new Euler4();
System.out.print(“Largest Palindrome = ” + e.Problem4()+ “\n”);
}
public String Problem4 ()
{
int product = 0;
int reverse = 0;
int biggest = 0;
for (int a=100; a <= 999; a++)
{
for (int b=100; b <=999; b++)
{
product = a * b;
reverse = Integer.parseInt(new StringBuffer(String.valueOf(product)).reverse().toString());
if ((product – reverse) == 0 && product > biggest)
{
biggest = product;
System.out.print(“Tested: ” + product +”\n”);
}
}
}
return String.valueOf(biggest);
}
}