//在控制台输出所有水“仙花数”,水仙花数必须满足 //1.水仙花数是一个三位数 //2.水仙花数的个位,十位,百位的数字立方和等于原数
package com.yuyang.loop;
public class ForDemo3 {
public static void main(String[] args) {
//在控制台输出所有水“仙花数”,水仙花数必须满足
//1.水仙花数是一个三位数
//2.水仙花数的个位,十位,百位的数字立方和等于原数
int sum=0;
for (int i=100;i<=999;i++){
int g=i%10;
int s=i/10%10;
int b=i/100;
if(g*g*g+s*s*s+b*b*b==i){
System.out.println("水仙花数:"+i);
}
}
}
}
com.yuyang.loop.ForDemo3
水仙花数:153
水仙花数:370
水仙花数:371
水仙花数:407
Process finished with exit code 0