Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,198,847 members, 7,969,547 topics. Date: Tuesday, 08 October 2024 at 09:50 AM |
Nairaland Forum / Science/Technology / Programming / Simple Java Problem (1837 Views)
Help A Java Newbie With This Simple Java Program / Please Solve This Java Problem. / Pls, Help Me In This Java Problem (2) (3) (4)
Simple Java Problem by eazyd(m): 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(m): 11:33am On Nov 20, 2012 |
Specially for @Javanian - love the way you code! |
Re: Simple Java Problem by eazyd(m): 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 |
. |
Re: Simple Java Problem by Javanian: 1:15pm On Nov 20, 2012 |
2 Likes |
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(m): 1:46pm On Nov 20, 2012 |
Javanian: As 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 |
(1) (Reply)
. / Life Of A Phone Programmer / Favorite Sections On User Profiles
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 8 |