Question: Write a static method called printSequenceTo that takes a target value as a parameter and then prints terms from a particular numerical sequence until they
Write a static method called printSequenceTo that takes a target value as a parameter and then prints terms from a particular numerical sequence until they add up to a value greater than or equal to the target and that returns the number of terms that were included. For example, if the following calls are made:
int n1 = printSequenceTo(3.0); int n2 = printSequenceTo(5.5);
The following output should be produced:
1/2 + 2/3 + 3/4 + 4/5 + 5/6 = 3.5500000000000003 1/2 + 2/3 + 3/4 + 4/5 + 5/6 + 6/7 + 7/8 + 8/9 = 6.171031746031746
The variable n1 is set to 5 because it took 5 terms from the sequence to get a sum that is at least 3.0. The variable n2 would be set to 8 because it took 8 terms to get a sum that is at least 5.5. You are to exactly reproduce the format of this output. Notice that the sum is not rounded.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
