欧拉计划 第4题
2014-03-02 16:15
218 查看
题目
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.
一个回文数指的是从左向右和从右向左读都一样的数字。最大的由两个两位数乘积构成的回文数是9009 = 91 * 99.
找出最大的有由个三位数乘积构成的回文数。
解答:该题将乘积变为数组,然后从前往后依次首尾比较。
Java程序
运行结果:906609
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.
一个回文数指的是从左向右和从右向左读都一样的数字。最大的由两个两位数乘积构成的回文数是9009 = 91 * 99.
找出最大的有由个三位数乘积构成的回文数。
解答:该题将乘积变为数组,然后从前往后依次首尾比较。
Java程序
public class N_4 { public static void main(String []args) { Integer num; int max =0; for(int i=100;i<1000;i++) { for(int j=i;j<1000;j++) { num = i*j; String str = num.toString(); char []c = str.toCharArray(); boolean flag = true; for(int k=0;k<c.length/2;k++) { if(c[k]!=c[c.length-1-k]) { flag = false; break; } } if(flag&&num>max) max = num; } } System.out.println(max); } }
运行结果:906609
相关文章推荐
- 欧拉计划第4题
- 中医之我见 和方舟子先生商讨 (第4部分)
- 12月第4周安全回顾 蠕虫肆虐圣诞新年 07年数据泄漏创新高
- “阿一web标准学堂”第4课:HTML和CSS基础知识(1)(附视频、课件、代码下载)
- Linux指导第4部分 用户管理
- 2006年百度之星程序设计大赛复赛第4题 彩球游戏(zuma) 题目及解法
- 第4课 面向对象下
- Flex 移动开发技巧与诀窍 第4部分:创建弹出式警告与其他蒙皮的弹出式控件
- 欧拉计划第5题
- 韩顺平_php从入门到精通_视频教程_第4讲_图像_表格_实际应用-菜谱_课堂练习-课程表_学习笔记_源代码图解_PPT文档整理
- Hibernate之第4解之-hibernate_集合映射
- 2013年第4周四
- 欧拉计划 题目24 (全排列)
- Jsp&Servlet入门级项目全程实录第4讲
- JSTL 入门,第4部分: 访问SQL和XML内容
- 2014第4周一
- 欧拉计划 第8题
- 欧拉计划16-20题
- C和指针第13章第4题
- 计蒜客 挑战难题 第4题:简单斐波那契