日期:2014-05-20 浏览次数:20657 次
public class Shuixianhuashu { public static void main(String[] args) { for (int i = 100; i < 1000; i++) { int a = i / 100; int b = i / 10 % 10; int c = i % 10; if (Math.pow(a, 3) + Math.pow(b, 3) + Math.pow(c, 3) == i) System.out.println(i + "是水仙花数"); } } }
------解决方案--------------------
public class Test {
public static void main(String[] args) {
int a,b,c;
for(int i=100; i<1000; i++) {
a = i/100;
b = (i-a*100)/10;
c = i-a*100-b*10;
if(i == a*a*a + b*b*b + c*c*c) {
System.out.println(i);
}
}
}
}