Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package problems;
- /*
- ============================================================================
- Name : Problem1.java
- Author : Catarina Moreira
- Copyright : Catarina Moreira all rights reserved
- Description : Project EULER problem 4: Largest palindrome product
- ============================================================================
- */
- public class Problem4
- {
- /*
- * A palindromic number reads the same both ways.
- * The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.
- *
- * Find the largest palindrome made from the product of two 3-digit numbers.
- *
- */
- public int findPalindrome( )
- {
- int largest_pal = 0;
- for( int i = 100; i < 1000; i++ )
- for( int j = 100; j < 1000; j++)
- if( reverse(i * j) == (i*j) && (i * j) > largest_pal )
- largest_pal = i*j;
- return largest_pal;
- }
- public int reverse( int n )
- {
- int reversedNum = 0;
- while( n !=0)
- {
- reversedNum = reversedNum*10 + n % 10;
- n = n/10;
- }
- return reversedNum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement