JAVA基础学习-寻找水仙花数

水仙花数定义:
1. 一定是3位数
2. 每一位的立方,加起来恰好是这个数本身,比如153=1*1*1+5*5*5+3*3*3

for (int i = 100; i < 999; i++) {
int baiwei = i/100%10;
int shiwei = i/10%10;
int gewei = i%10;
if (i==baiwei*baiwei*baiwei+shiwei*shiwei*shiwei+gewei*gewei*gewei) {
System.out.println("找到水仙花数为"+i);
}
}

猜你喜欢

转载自www.cnblogs.com/leemlzm/p/12044447.html
今日推荐