Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Investigations into pi Thirty-five digits of pi are sufficient to calculate the circumference of the universe to within the size of a hydrogen nucleus. In
Investigations into pi Thirty-five digits of pi are sufficient to calculate the circumference of the universe to within the size of a hydrogen nucleus. In other words, finding the value of pi to ten quadrillion digits is pretty much the definition of pointless. But people seem to enjoy doing it anyhow. How? There are a number of methods, but one common approach is to discover an infinite series that converges to the correct value. Here's one that has been around for hundreds of years, known as the Gregory series: pi/4 = sigma_k = 1^infinity (-1)^k + 1/2k - 1 = 1 - 1/3 + 1/5 - 1/7 + Write a program called Gregory.java that takes a number n specified by the user (via the command line) and calculates pi using the first n terms of the Gregory series. The program should print this approximate value of pi, as well as the percentage error between this value and the one provided by Java in the constant Math.PI. $ java Gregory 10 Pi according to Gregory series: 3.0418396189294032 This differs from Java's value by 3.175237710923643 percent. $ java Gregory 1000 Pi according to Gregory series: 3.140592653839794 This differs from Java's value by 0.03183098066059948 percent
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started