Iteration refers to the repetition of the same lines of code until a condition is satisfied. To…
Iteration refers to the repetition of the same lines of code until a condition is satisfied. To illustrate, in Listing 12.2 is a code that computes 1/1 − x for x2
The summation of terms is repeated 1,000 times or until the new terms have an insignificant effect on the sum (xn
a. Enter, compile, and execute Iterate.java. Check that it runs with no errors.
b. Try several positive values of x
c. See how close you are able to get to x 1 before the algorithm fails, namely, 1,000 summations are made.
d. The series (12.12) is valid for negative x values, but the code has assumed that x > 0. Modify the program so that it will work for negative x, and check your results for x = −0.5, −0.1, and −0.9.