-4
A
回答
0
该解决方案非常前沿,它只是1M以下所有回文数字的暴力破解。
public class Main {
public static void main(String[] args) {
int count=0;
for (int i = 0; i < 1_000_000; i++) {
if (isDoublePalindrome(""+i)) {
count+=i;
}
}
System.out.println(count);
}
public static boolean isPalindrome(String N){
return new StringBuilder(N).reverse().toString().equals(""+N);
}
public static String toBinary(String N){
return Long.toBinaryString(Long.parseLong(N));
}
public static boolean isDoublePalindrome(String N){
if(isPalindrome(N) && isPalindrome(toBinary(N))) return true;
return false;
}
}
0
剩下的就是你的,但这里是它会告诉你一个int
是否在给定的基本回文的方法;假设参数是正确的,即要检查的数字是> = 0且基数> 0:
public static isPalindromInBase(final int before, final int base)
{
int after = 0;
for (int i = before; i > 0; i /= base) {
after += i % base;
after *= base;
}
return before == after;
}
相关问题
- 1. 爪哇 - 基本流的forEach
- 2. 爪哇 - 基于毫秒
- 3. 爪哇 - 的getMessage()返回null
- 4. 爪哇从文件
- 5. 爪哇谷歌地图
- 6. 爪哇回归按钮
- 7. 爪哇较长的文字
- 8. 爪哇的StringIndexOutOfBoundsException
- 9. FTPClient - 爪哇,上传文件
- 10. 爪哇搜索文件
- 11. 爪哇 - 读取XML文件
- 12. 爪哇:同键映射的地图
- 13. 爪哇 - 加载不同的地图
- 14. 爪哇 - 基于多定界符
- 15. 硒,爪哇,waitForCondition
- 16. 爪哇thesauraus
- 17. 爪哇 - 在
- 18. 爪哇 - 由
- 19. 爪哇:enum toString()
- 20. 爪哇排序
- 21. 爪哇 - 并行
- 22. 爪哇优化
- 23. 爪哇 - 每行
- 24. 爪哇从长
- 25. ApplicationException的 - 爪哇 - 休眠 - 回滚相关
- 26. 爪哇 - 从顾客返回的值
- 27. 爪哇:一个三角形
- 28. 爪哇这个参数
- 29. 爪哇 - 从JList的
- 30. 爪哇 - 空的ResultSet
以10为底数生成回文。总结它们。在基数2中生成回文。转换为基数10,对它们进行求和。加两个总和。 – Deltharis 2014-11-02 22:40:39
先阅读:[如何问](http://stackoverflow.com/help/how-to-ask) – 2014-11-02 22:41:31
@Deltharis你显然是错的。 OP:什么问题?循环所有数字低于100万。检查回文基座10.检查回文基座2.如果两者都满意,请加入蓄电池。 – maaartinus 2014-11-02 22:46:34