Results 1 to 2 of 2
- 10-28-2011, 07:46 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 5
- Rep Power
- 0
Code to determine how many elements of a givine infinite series are required to
find the value of pi, accurate to 5 decimal places?
Sorry the title got cut off. If not the code I'd appreciate a step by step explanation of how to do this problem.
Here it is:
Write a java project (Application) with just a driver class. This class should have a default constructor and a main method which calls it.
This project should determine how many elements of the infinite series shown below are required to find the value of pi, accurate to 5 decimal places.
pi / 4 = 1 - 1 / 3 + 1 / 5 - 1 / 7 + 1 / 9 - 1 / 11 + ...
You must use the following constant
private static final double PI = 3.14159;
and your program must use a do loop.
Your output should look like this:
Value of pi = 3.14159
Number of elements of the series = 130657
The value of pi is not the value of the constant, instead it is the value of the series rounded to 5 places.
Thanks in advance for your time.
- 10-28-2011, 08:15 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: Code to determine how many elements of a givine infinite series are required to
First write a bit of code that creates the series 1/1-1/3+1/5-1/7 ... and work from there (the numerator flips between 1 and -1 while the deniminator takes the values 1, 3, 5, 7 ...).
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Help required in executing the following code
By vivekdarshan in forum Advanced JavaReplies: 6Last Post: 01-24-2011, 12:24 PM -
Help required in executing the following code
By vivekdarshan in forum Advanced JavaReplies: 0Last Post: 01-23-2011, 09:34 AM -
How to determine the size of object (facilityExceptionData) in code below
By neetigya in forum Advanced JavaReplies: 6Last Post: 10-11-2010, 01:59 PM -
Getting ExceptionInInitializer exception when i am trying to code a time series chart
By neeraj.singh in forum AWT / SwingReplies: 2Last Post: 02-17-2009, 03:20 PM -
code required
By baba in forum JavaServer Pages (JSP) and JSTLReplies: 6Last Post: 10-06-2008, 03:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks