Project Euler 4
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.
A palindromic number→回分数
2-digit numbers→2桁の数
the product→積
回分数は、両側から同じように読む。
2つの2桁の数の積で出来た一番大きい回文は、9009で、91と99である。
2つの3桁の数の積で出来た一番大きい回文を探せ!
javaで以下略
public class Euler4 { public static void main(String[] args) { System.out.println(getMaxPalindromic(100,999)); } public static int getMaxPalindromic(int min,int max) { int maxPal = 0; int[] nums = new int[2]; for(int i=min;i<=max;i++) { for(int n=min;n<=max;n++) { if(getPalindromicFromProductOf2nums(i, n) > maxPal) { maxPal = getPalindromicFromProductOf2nums(i, n); nums[0] = i; nums[1] = n; } } } System.out.println(nums[0] +","+ nums[1]); return maxPal; } public static int getPalindromicFromProductOf2nums(int a,int b) { int result = a*b; String c = String.valueOf(result); String d = ""; for(int i=c.length()-1;i>=0;i--) { d += c.charAt(i); } if(c.equals(d)) return result; else return 0; } }
Congratulations, the answer you gave to problem 4 is correct.
正解だった。