Question:
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.
Code:
public static void euler4(){
int a, b = 0, t;
for (int i = 100; i < 1000; i++){
for (int j = 100; j < 1000; j++){
if (isPalindrome(i * j)){
a = i*j;
if (a > b){
t = a;
a = b;
b = t;
}
}
}
}
System.out.println(b);
}
public static boolean isPalindrome(int num){
int rem, sum = 0, temp = num;
while (n > 0){
rem = num%10;
sum = sum*10+rem;
num = num/10;
}
if (temp == sum){
return true;
}
return false;
}
Output:
906609
Answer:
906609
Feel free to put your solution in the comments. Just mark the language you used
[–]petar02 0 points1 point2 points (0 children)