java经典习题3

/*
题目:打印出所有的 "水仙花数 ",所谓 "水仙花数 "是指一个三位数,其各位数字立方和等于该数本身。
*/
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;
}
}
}
}

猜你喜欢

转载自www.cnblogs.com/zhuozige/p/12357885.html