I was trying to solve project Euler problem 4 which is:
A palindromic number reads the same both ways. The largest palindrome made from the product of tw
You are iterating for loop with number from 998001 to 10000 in that some number may not be a product two 3-digit number.
You for should multiply two 3-digit number and than compare it if that number is palindrome or not.
Your for loop code should be :
for(int i=999;i>=100;i--)
{
int k = i-1;
int product = i * k;
System.out.println(i+" * "+k+" = "+product);
if(isPalindrome(product)==true){
System.out.println("palindrum number "+product);
System.out.println("Product of : "+i+" * "+k);
break;
}
}
This will gives you largest palindrome number of which is product of two 3-digit number.
Output is :
palindrum number 289982
Product of : 539 * 538
This will true if both number is different while you multiply.
If you want to include same number product to check that is palindrome or not than there may be little change in above code.
For that code should be :
for(int i=999;i>=100;i--){
int k = i;
int product = i * k;
System.out.println(i+" * "+k+" = "+product);
if(isPalindrome(product)==true){
System.out.println("palindrum number "+product);
System.out.println("Product of : "+i+" * "+k);
break;
}
else{
k = i - 1;
product = i * k;
System.out.println(i+" * "+k+" = "+product);
if(isPalindrome(product)==true){
System.out.println("palindrum number "+product);
System.out.println("Product of : "+i+" * "+k);
break;
}
}
}
Which give you output like :
palindrum number 698896
Product of : 836 * 836
I think this is what you need to do.