码迷,mamicode.com
首页 > 其他好文 > 详细

Problem 004

时间:2018-02-06 12:54:26      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:gpo   project   system   cte   strong   log   static   就是   span   

欧拉计划----https://projecteuler.net/


 

 

最大回文乘积

回文数就是从前往后和从后往前读都一样的数。由两个2位数相乘得到的最大回文乘积是 9009 = 91 × 99。

找出由两个3位数相乘得到的最大回文乘积。

public class Problem4 {
    
    static int cal() {
        int max=0;
        int num=0;

        for (int i = 100; i < 1000; i++) {
            for (int j = 100; j < 1000; j++) {
                num=i*j;
                String s1=new StringBuilder(String.valueOf(num)).reverse().toString();
                if(s1.equals(num+"")) {
                    if(num>max) {
                        max=num;
                    }
                }
            }
        }
        return max;
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        System.out.println(cal());
        long end = System.currentTimeMillis();
        System.out.println("runtime:" + (end - start));
    }

}

 

Problem 004

标签:gpo   project   system   cte   strong   log   static   就是   span   

原文地址:https://www.cnblogs.com/Alice-Thinker/p/8421487.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!