-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2452a9f
commit 03de691
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package algorithms; | ||
|
||
|
||
/** | ||
* A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. | ||
* Find the largest palindrome made from the product of two 3-digit numbers. | ||
* | ||
* @author joeytawadrous | ||
*/ | ||
public class LargestPalindromeProduct { | ||
|
||
public static void main(String[] args) { | ||
System.out.println(sixDigitPalindrome()); | ||
} | ||
|
||
public static int sixDigitPalindrome() { | ||
|
||
int max = 0; | ||
|
||
for(int i = 999; i > 100; i--) { | ||
|
||
for(int j = i; j > 100; j--) { | ||
String number = Integer.toString((i * j)); | ||
|
||
if(number.length() == 6 | ||
&& number.charAt(0) == number.charAt(5) | ||
&& number.charAt(1) == number.charAt(4) | ||
&& number.charAt(2) == number.charAt(3) | ||
&& Integer.parseInt(number) > max) { | ||
max = i * j; | ||
} | ||
} | ||
} | ||
|
||
return max; | ||
} | ||
} |