解题思路:这个题呢,他在4150之前是没有五次方数,而到了194979之后的也没有五次方数,所以for的初始值和结束值,所有就用for循环,然后来分解for循环的i
注意事项: int类型四位数的分解是int a=i/1000; 五位数的分解是 int a=i/10000;
int b=(i/100)%10; int b=(i/1000)%10;
int c=(i/10)%10; int c=(i/100)%10; int d=i%10; int d=(i/10)%10;
int e=i%10;
参考代码:
public class Text { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub for (int i = 4150; i <=194979; i++) { if (i>=4150&&i<10000) { int a=i/1000; int b=(i/100)%10; int c=(i/10)%10; int d=i%10; if (Math.pow(a, 5)+Math.pow(b, 5)+Math.pow(c, 5)+Math.pow(d, 5)==i) { System.out.println(i); } } else if (i>=10000&&i<100000) { int a=i/10000; int b=(i/1000)%10; int c=(i/100)%10; int d=(i/10)%10; int e=i%10; if (Math.pow(a, 5)+Math.pow(b, 5)+Math.pow(c, 5)+Math.pow(d, 5)+Math.pow(e, 5)==i) { System.out.println(i); } } else { int a=i/100000; int b=(i/10000)%10; int c=(i/1000)%10; int d=(i/100)%10; int e=(i/10)%10; int f=i%10; if (Math.pow(a, 5)+Math.pow(b, 5)+Math.pow(c, 5)+Math.pow(d, 5)+Math.pow(e, 5)+Math.pow(f, 5)==i) { System.out.println(i); } } } } }
0.0分
2 人评分
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:605 |
矩形面积交 (Java代码)浏览:1213 |
分糖果 (C++代码)浏览:1438 |
C语言训练-大、小写问题 (C语言代码)浏览:724 |
勾股数 (C语言代码)浏览:799 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:663 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:695 |
多组数据新方法浏览:355 |
P1001 (Java代码)浏览:687 |
【蟠桃记】 (C语言代码)浏览:805 |