For语句:
public class hw3{
public static void main(String args[]){
double x,y=1,z=0;
for(x=1;x<=20;x++){
y=1/x*y;
z=z+y;
System.out.println(z);
}
}
}
While语句:
public class hw3{
public static void main(String args[]){
double x=1,y=1,z=0;
do{
y=1/x*y;
z=z+y;
x++;
}
while(x<=20);
System.out.println(z);
}
}