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.
译文:
利用相同的方法寻找回文数。两个2位数字的乘积的最大回文是9009=91×99。
得到两个3位数字的乘积的最大回文。
import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) { List<Integer> list = new ArrayList<Integer>(); int a=0; for(int i=99;i<1000;i++) { for(int j=99;j<1000;j++) { list.add(j*i); } } List<Integer> lis = new ArrayList<Integer>(); for(int i=0;i<list.size();i++) { if(list.get(i)>100000) { if(list.get(i) % 10 ==list.get(i) / 100000 && (list.get(i) /10)% 10 ==(list.get(i) / 10000)%10 && (list.get(i) / 1000)%10 ==(list.get(i) / 100)%10) { lis.add(list.get(i)); } } } int max=lis.get(0); for(int i=0;i<lis.size();i++) { if(max<lis.get(i)) { max=lis.get(i); } } System.out.println(max); } }
结果:
906609