Java 输出所有的水仙花数
输出所有的水仙花数(三位数,各位数字的立方和等于自身)
public class Test {
public static void main(String[] args) {
int m;
System.out.print("所有的水仙花数为:");
for (int n = 100; n < 1000; n++) {
m = (int) Math.pow(n / 100, 3) + (int) Math.pow(n / 10 % 10, 3) + (int) Math.pow(n % 10, 3);
if (n == m) {
System.out.print(n + " ");
}
}
}
}
还没有评论,来说两句吧...