The question is:

You can approximate e by using the following series

1+1/1!+1/2!+1/3!+1/4!+⋯

Write a program that finds out how many TERMS of this series you need before you first get 2.71828183 approximately.

I am having troubles writing my actual program. I am trying to loop and test then count until i hit the number but i feel as if my program is not what the question is asking. I get that the question is asking how many terms are needed to find the approximation of e and not the number given because the actual approximation is 2.71828182845904523, which is precise.

Below is my program. I would really appreciate some feedback.

Code:`public static void main(String[] args) {`

// TODO Auto-generated method stub

double sum=1;

double k=1;

while (k<=10)

{

sum=sum+(1/factorial (k));

k++;

if (sum>=2.71828183)

break;

}

double term=k-1;

JOptionPane.showMessageDialog (null,"You need "+term+" terms before you first get 2.71828183 approximately. ");

}

public static double

factorial (double k) {

double fact=1;

for (double j=1;j<=k;j++)

fact=fact*j;

return fact;

}

}