例3-5和例3-6
public class Example3_5{
public static void main(String args[]){
double sum=0,item=1;
int i=1;
while(i<=1000){
sum=sum+item;
i++;
item=item*(1.0/i);
}
sum=sum+1;
System.out.println("e="+sum);
sum=0;
i=1;
item=1;
do{
sum=sum+item;
i++;
item=item*(1.0/i);
}while(i<=1000);
sum=sum+1;
System.out.println("e="+sum);
}
}
public class Example3_6{
public static void main(String args[]){
int sum,i,j;
for(i=1;i<=1000;i++){
for(j=1,sum=0;j<=i/2;j++){
if(i%j==0){
sum=sum+j;
}
}
if(sum==i){
System.out.printf("%8d是一个完数%n",i);
}
}
}
}