求e^x的近似值

时间:2021-10-15 18:32:44
package com.test.common;

public class TestE {

	public static double getE(int x)
	{
		int ncount=1;
		int xcount=x;
		double count=1;
		
		int n=1;
		
		while(n<10)
		{
			ncount=ncount*n;
			xcount=xcount*x;
			count+=(double)xcount/(double)ncount;
			
			n++;
		}
		
		return count;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println(getE(2));
	}

}