# Thread: Stuck on a probably simple question.

1. Member Join Date
Jan 2011
Posts
3
Rep Power
0

## Stuck on a probably simple question.

I'm stuck on the following question:

The value of the mathematical constant e, which is 2.718281828459045, can be approximated as an infinite series as follow:
e = 1 + 1/1! + 1/2! + 1/3! + ...., where n! = 1×2×3×4×....×n.
Write a program that approximate e. Your program should keep adding terms until the value of the current term becomes less than a small floating-point number entered by the user. Test your program using the following small floating-point numbers.
0.01, 0.001, 0.0001, 0.00001, 0.000001, 0.0000001, 0.00000001, 0.000000001, 0.0000000001, and 0.00000000001.
You should print the approximated value of e, as well as the number of terms required to generate this value.
This is what I have so far:

Java Code:
```import java.util.Scanner;

public class MathConstant

{

public static void main(String[] args)

{

Scanner input = new Scanner(System.in);

System.out.println("Enter an integer value: ");
int value = input.nextInt(); // Getting the value from user input
double number = 1;
double total = 0;

while (number < value)

{

number += 1;
total ++

}

}

}```
All I really need help with is how to I incorporate a factorial in a loop? How would I do like 400! without writing the whole thing out?  Reply With Quote

2. ## It will provide you an explanation of how to calculate factorial. Or if you are lazy I'm sure google can even turn up the code.  Reply With Quote

3. ## Recursion!  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•