北斗七星数-Java代码实现
public static void main(String[] args) {
for(int i=1000000; i<=9999999; i++) {
long x1 = (long) Math.pow(((long)(i/1000000)), 7);
long x2 = (long) Math.pow(((long)(i%1000000/100000)), 7);
long x3 = (long) Math.pow(((long)(i%100000/10000)), 7);
long x4 = (long) Math.pow(((long)(i%10000/1000)), 7);
long x5 = (long) Math.pow(((long)(i%1000/100)), 7);
long x6 = (long) Math.pow(((long)(i%100/10)), 7);
long x7 = (long) Math.pow(((long)(i%10)), 7);
if((x1+x2+x3+x4+x5+x6+x7) == i) {
System.out.println(i);
}
}
}
结果: