package com.zhidi.loop;
/*计算1000以内一共有多少个水仙花数?
水仙花数:
(1)它是一个三位整数
(2)个位数字的立方+十位数字的立方+百位数字的立方=它本身
如:153=1的立方+5的立方+3的立方*/
public class Shuixianhuashu {
public static void main(String[] args){
int a,g,s,b;
int temp=0;//局部变量使用前要先进行初始化;
long l1=System.currentTimeMillis();
for(a=100;a<1000;a++){
g=a%100;
s=a / 10 % 10;
b=a/100;
if(Math.pow(g,3)+Math.pow(s, 3)+Math.pow(b, 3)==a){
temp++;
System.out.println(a+"是水仙花数");
}
}long l2=System.currentTimeMillis();
System.out.println("1000以内的水仙花数共有"+temp+"个");
System.out.println("共耗时"+(l2-l1)+"毫秒");
}
}