Results 1 to 3 of 3
- 02-11-2011, 12:16 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 3
- Rep Power
- 0
Stuck on a probably simple question.
I'm stuck on the following question:
This is what I have so far: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! = 14....譶.
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.
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?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 ++ } } }
- 02-11-2011, 12: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.
- 02-11-2011, 05:50 AM #3
Similar Threads
-
Simple Question
By stackptr89 in forum New To JavaReplies: 13Last Post: 01-29-2011, 05:35 PM -
First Assignment and already stuck....Newbie Question
By Danieldcc in forum New To JavaReplies: 5Last Post: 09-24-2010, 11:44 PM -
very simple Question
By arsenal4ever_11 in forum NetBeansReplies: 2Last Post: 05-27-2010, 08:51 PM -
some simple question?
By jperson in forum New To JavaReplies: 4Last Post: 05-03-2010, 05:32 PM -
Stuck - simple program
By dirtycash in forum New To JavaReplies: 4Last Post: 11-24-2008, 07:44 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks