我下面的解法比你那个简单很多:
public class WanShu{
public static void main(String args[]){
int n=6,z=0,k,sum=0,i=0,j=0;
Integer zi[]=new Integer[100];
for(n=1;n<=1000;n++){
k=1;
sum=0;
while(k<n)
{
z=k++;
if ((n%z)==0){
sum+=z;
zi[i++]=z;
j=i;
}
}
if (sum==n) {
System.out.print(n+" its factors are :");
for(i=0;i<j;i++)
System.out.print(zi[i]+",");
System.out.println() ;
}
i=0 ;
}
}
}
希望对你有所帮助,学习愉快!谢谢! |