Results 1 to 2 of 2
  1. #1
    j@y
    j@y is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Default 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.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,310
    Blog Entries
    7
    Rep Power
    20

    Default 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,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Help required in executing the following code
    By vivekdarshan in forum Advanced Java
    Replies: 6
    Last Post: 01-24-2011, 12:24 PM
  2. Help required in executing the following code
    By vivekdarshan in forum Advanced Java
    Replies: 0
    Last Post: 01-23-2011, 09:34 AM
  3. Replies: 6
    Last Post: 10-11-2010, 01:59 PM
  4. Replies: 2
    Last Post: 02-17-2009, 03:20 PM
  5. code required
    By baba in forum JavaServer Pages (JSP) and JSTL
    Replies: 6
    Last Post: 10-06-2008, 03:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •