You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
556 B

4 years ago
/**
* ex
* e^x=1+x/1!+x^2/2!+x^3/3!++x^n/n! 
**/
public class CalculateEx {
public static double calcalate(int x){
int n=1; //n用来算阶乘
long f=1; //总阶乘
double sum=1.0,temp=1.0; //sum为最终值temp算分子的次方
do{
f= f*n ;//阶乘
n++ ;
temp *= x; //计算次方
sum += temp / f;
} while(1.0/f>1e-6);
//System.out.println("e^"+x+"="+sum);
return sum;
}
}