编写程序:用三重循环求出所有水仙花数。

来源:百度知道 编辑:UC知道 时间:2024/06/28 11:54:32
急用

为什么要三层循环,一层足矣!!!!!!
public class SXH {

public static void main(String[] args) {

for(int n = 100;n<1000;n++){
int i , j , k;

i = n%10;
j = n%100/10;
k = n/100;
if(n == i*i + j*j + k*k) {
System.out.println(n+"是一个水仙花数!");
}
}
}

}
希望对你有帮助!!!!

for n=100 to 999
a=int(n/100)
b=int(mod(n,100)/10)
c=mod(mod(n,100),10)
if a*a*a+b*b*b+c*c*c=n
?alltrim(str(a))+alltrim(str(b))+alltrim(str(c))
endif
endfor