View difference between Paste ID: pM0Bcas4 and rTCmwFcj
SHOW: | | - or go back to the newest paste.
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 {
12+
public class Problem4 
13
{
14
15
   /*
16
    * A palindromic number reads the same both ways.
17
    *  The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.
18
    *  
19
    *  Find the largest palindrome made from the product of two 3-digit numbers.
20
    *  
21
   */
22
	
23
   public int findPalindrome( )
24
   {
25
      int largest_pal = 0;
26
		
27
      for( int i = 100; i < 1000; i++ )
28
         for( int j = 100; j < 1000; j++)
29
	    
30
            if( reverse(i * j) == (i*j) && (i * j) > largest_pal )
31
	       largest_pal = i*j;
32
33
      return largest_pal;
34
   }
35
	
36
   public int reverse( int n )
37
   {
38
      int reversedNum = 0;
39
      while( n !=0)
40
      {
41
         reversedNum = reversedNum*10 + n % 10;
42
	 n = n/10;
43
      }
44
45
      return reversedNum;
46
   }
47
}