Results 1 to 3 of 3
 02112011, 01:16 AM #1Member
 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 floatingpoint number entered by the user. Test your program using the following small floatingpoint 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.
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 ++ } } }
 02112011, 01:20 AM #2
Google
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.
 02112011, 06:50 AM #3
Similar Threads

Simple Question
By stackptr89 in forum New To JavaReplies: 13Last Post: 01292011, 06:35 PM 
First Assignment and already stuck....Newbie Question
By Danieldcc in forum New To JavaReplies: 5Last Post: 09252010, 12:44 AM 
very simple Question
By arsenal4ever_11 in forum NetBeansReplies: 2Last Post: 05272010, 09:51 PM 
some simple question?
By jperson in forum New To JavaReplies: 4Last Post: 05032010, 06:32 PM 
Stuck  simple program
By dirtycash in forum New To JavaReplies: 4Last Post: 11242008, 08:44 PM
Bookmarks