Guest User

Untitled

a guest
Jul 30th, 2013
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. package problems;
  2.  
  3. /*
  4.  ============================================================================
  5.  Name        : Problem1.java
  6.  Author      : Catarina Moreira
  7.  Copyright   : Catarina Moreira all rights reserved
  8.  Description : Project EULER problem 4: Largest palindrome product
  9.  ============================================================================
  10. */
  11.  
  12. public class Problem4 {
  13.  
  14.    /*
  15.     * A palindromic number reads the same both ways.
  16.     *  The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.
  17.     *  
  18.     *  Find the largest palindrome made from the product of two 3-digit numbers.
  19.     *  
  20.    */
  21.    
  22.    public int findPalindrome( )
  23.    {
  24.       int largest_pal = 0;
  25.        
  26.       for( int i = 100; i < 1000; i++ )
  27.          for( int j = 100; j < 1000; j++)
  28.        
  29.             if( reverse(i * j) == (i*j) && (i * j) > largest_pal )
  30.            largest_pal = i*j;
  31.  
  32.       return largest_pal;
  33.    }
  34.    
  35.    public int reverse( int n )
  36.    {
  37.       int reversedNum = 0;
  38.       while( n !=0)
  39.       {
  40.          reversedNum = reversedNum*10 + n % 10;
  41.      n = n/10;
  42.       }
  43.  
  44.       return reversedNum;
  45.    }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment