Package practice;
/* Use while loop to compute 1+1/2!+1/3!+...+1/20! A is used to store one of the first n factorial points sum is used to accumulate and/or public class Whiledemo {The public static void main (string[] args) {/*i=i+1 is a short form of i+=1;
Qualitative difference: If I is the short type, + =: automatic type promotion, and = will not be so short i=0;
i+=1;//compilation passed, type elevation i=i+1;//compilation failed because this is the assignment operation, I is the short type, and 1 is the type int by default/double = 0,a = 1;//because it is fractional, so the double type int i = 1;
while (i <=) {sum +=a;
i++;
A*= (1.0/i);//Make a value change System.out.println (a*i);
} System.out.println (sum);
System.out.println ("_________________________");
Fordemo.main (args);
System.out.println (Text.jiecheng (4)); } class fordemo{public static void Main (string[] args) {double = 0,a = 1; for (int i = 1; I <=20; i++) {sum
+=a;
A*= (1.0/i);
System.out.println (A*i);
} sum--;
SYSTEM.OUT.PRINTLN (sum); }//Recursive procedure: Inefficient, judgment affects performance class text{public static void Main (string[] args) {//double sum=0.0,count=1.0; (count<=20.0)
{//sum+=1.0/(Jiecheng (count));//count++;//}//System.out.print (sum);
}
public static long Jiecheng (long sum) {/* for (int i=1;i<=c;i++) {sum*=i;
}*/if (sum<=1) return 1;
Return Sum*jiecheng (sum-1);
}
}