//水仙花数:
//水仙花数是指一个 3 位数,它的每个位上(个位、十位、百位)的数字的 3次幂之和等于它本身
public class SuiXianHuaShu {
public static void main(String[] args) {
int n1,n2,n3;
System.out.print("水仙花谁为:");
for(int i=100;i<=999;i++) {
n1=i/100;//百位数
n2=i/10%10;//十位数
n3=i%10;//个位数//在Java中使用数学的几次幂的时候输入math.这个点后会有相应的提示
if(Math.pow(n1,3)+Math.pow(n2,3)+Math.pow(n3,3)==i) {
System.out.print(i+" ");
}
}
}
}
结果显示:
水仙花谁为:153 370 371 407
输出水仙花数
猜你喜欢
转载自blog.csdn.net/qq_45696288/article/details/104864602
今日推荐
周排行