# Stuck on a probably simple question.

• 02-11-2011, 01:16 AM
kmjt
Stuck on a probably simple question.
I'm stuck on the following question:

Quote:

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:

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?
• 02-11-2011, 01:20 AM
Junky