commit
df91a4dd57
@ -0,0 +1,25 @@
|
||||
package e的x次方;
|
||||
public class power{
|
||||
|
||||
public static int factorial(int n){
|
||||
int factorial=1;
|
||||
int counter=1;
|
||||
while (counter<1+n){
|
||||
factorial*=counter+1;
|
||||
counter++;
|
||||
}
|
||||
return factorial;
|
||||
}
|
||||
public static double ex(int n,int x){
|
||||
double ex=1.0;
|
||||
int counter=1;
|
||||
while (counter<=n){
|
||||
ex+=(double)Math.pow(x,counter)/factorial(counter);
|
||||
counter++;
|
||||
}
|
||||
return ex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue