package practiceGO;
/*
*5、算水仙花数(100-999):表示三位数的数字,个位的三次方+十位的三次方+百位的三次方=这个数本身
*/
public class Cto {
public static void main(String[] args) {
int first,second,third;
for(int i=100; i<=999; i++){
first = (i/100);
second = (i-first*100)/10;
third = i%10;
if (Math.pow(first, 3)+Math.pow(second, 3)+Math.pow(third, 3) == i) {
System.out.println(i+"是水仙花数");
}
}
}
}
运行结果:
153是水仙花数
370是水仙花数
371是水仙花数
407是水仙花数
转载于:https://blog.51cto.com/11317783/1762315