Simple Java Problem - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Simple Java Problem (1915 Views)
| Simple Java Problem by eazyd(op): 11:30am On Nov 20, 2012 |
Estimate and print the mathematical constant e (equal to 2.71828). You can estimate its value using the formula: e = 1 + 1/1! + 1/2! + 1/3! +1/4! + ....+ 1/k! + ... Quit looping when the term 1/k! becomes less than 1E-04. |
| Re: Simple Java Problem by eazyd(op): 11:33am On Nov 20, 2012 |
Specially for @Javanian - love the way you code! ![]() |
| Re: Simple Java Problem by eazyd(op): 11:42am On Nov 20, 2012 |
solution- public class ConstantValue { public static void main (String [] args) { // declare data; double e; double k; double denom; double term; // initialize the data; e = 1; k = 0; denom = 1; do { k++; denom*= k; term = 1/denom; e += term; System.out.println("The value of constant e = "+e); } while (term >= 1E-04); } } |
| Re: Simple Java Problem by Nobody: 12:45pm On Nov 20, 2012*. Modified: 9:58am On Apr 03, 2017 |
. |
| Re: Simple Java Problem by Javanian: 1:15pm On Nov 20, 2012*. Modified: 1:30pm On Nov 20, 2012 |
|
| Re: Simple Java Problem by Javanian: 1:23pm On Nov 20, 2012 |
eazyd: Specially for @Javanian - love the way you code!Am Flattered ![]() |
| Re: Simple Java Problem by eazyd(op): 1:46pm On Nov 20, 2012 |
Javanian: Am FlatteredAs usual, you delivered promptly! |
| Re: Simple Java Problem by xcitedjay(m): 8:45pm On Nov 24, 2012 |
Just thought I should add a solution using a while loop public class ConstantValue{ |
| Re: Simple Java Problem by Javanian: 3:25am On Jul 25, 2014 |
bump |
Help A Java Newbie With This Simple Java Program • Please Solve This Java Problem. • Pls, Help Me In This Java Problem • 2 • 3 • 4
3 Reasons Why You Should Not Miss Becoming an App Developer today (pics) • What Next After Learning Core JAVA, HTML And CSS • What Is Ui And Ux

