Question: Using the Java programming language, calculate the value of pi from the infinite series pi = 4 - 4/3 + 4/5 - 4/7 + 4/9

Using the Java programming language, calculate the value of pi from the infinite series pi = 4 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 + ... Print a table that shows the value of pi approximated by computing one term of this series, by two terms, by three terms, and so on. Use default precision for output (i.e. do not set any decimal precision). Start by asking the user how many terms of the series to compute to, and then let the user enter the information. Use this to print a table of the first N terms of the series (where N is the data entered by the user). Assume the user's input will be a non-negative integer. (see sample output)

Sample Run (Sample user input is bolded)

Exercise 5.20: 'Approximating PI'

Compute to how many terms of the series? 20 terms

PI approximation

1 4.0

2 2.666666666666667

3 3.466666666666667

4 2.8952380952380956

5 3.3396825396825403

6 2.9760461760461765

7 3.2837384837384844

8 3.017071817071818

9 3.2523659347188767

10 3.0418396189294032

11 3.232315809405594

12 3.058402765927333

13 3.2184027659273333

14 3.0702546177791854

15 3.208185652261944

16 3.079153394197428

17 3.200365515409549

18 3.0860798011238346

19 3.1941879092319425

20 3.09162380666784

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!