java经典习题3

时间:2020-02-24 18:07:24   收藏:0   阅读:54

/*
题目:打印出所有的 "水仙花数 ",所谓 "水仙花数 "是指一个三位数,其各位数字立方和等于该数本身。
*/
public class Class3 {
public static void main(String[] args){
int a;
int b;
int c;
System.out.println("水仙花数为:");
for(int i = 100; i <= 999; i++){
a = i/100;
b = (i - a*100)/10;
c = i - 100*a - 10*b;
if(i == (Math.pow(a,3) + Math.pow(b,3) + Math.pow(c,3))){
System.out.println(i);
}else{
continue;
}
}
}
}

原文:https://www.cnblogs.com/zhuozige/p/12357885.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!