document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*A palindromic number reads the same both ways.
  2.  
  3. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91*99.
  4.  
  5. Find the largest palindrome made from the product of two 3-digit numbers.
  6. 2 digits :  10->99
  7. 3 digits : 100->999
  8. */
  9. import javax.swing.*;
  10. public class LargestPalindrome{
  11.     public static void main(String [] args){
  12.         long largestPalindrome=0;
  13.         long product;
  14.         for(long i=100;i<1000;i++)
  15.         {  
  16.             for (long j= 100;j<1000;j++)
  17.             {
  18.                 product = i*j;
  19.                 if (Palindrome(product))
  20.                 {  
  21.                     if (product>largestPalindrome)
  22.                     {
  23.                         largestPalindrome=product;
  24.                     }
  25.                 }
  26.             }
  27.         }
  28.         System.out.println("Largest palindrome made from the product of two 3-digit numbers: "+largestPalindrome);
  29.         }
  30.     public static boolean Palindrome(long aInt)
  31.     {
  32.     String str1= Long.toString(aInt);
  33.     String str2="";
  34.     int length = str1.length();
  35.     for (int i=length-1;i>=0;i--)
  36.     {
  37.         str2 += str1.charAt(i);
  38.     }
  39.     //System.out.println(str1+"\\n"+str2);
  40.     if (str1.equalsIgnoreCase(str2))
  41.         return true;
  42.     return false;
  43.     }
  44. }
');