3. To compute the square root of a given number n, Java starts with some approximation a and then computes the more accurate approximation m as follows:
1 / n \
m = - * | a + - |
2 \ a /
(For example, when we compute the square root of n = 2.0 and start with
a = 1.0, we get a more accurate approximation m = (1/2) * (1.0 + 2.0/1.0) = 1.5.)Assuming that n and a are already placed in the corresponding variables of type double, write a Java code statement for assigning the corresponding value to the variable m of type double. Explain, step-by-step, which arithmetic operations will be performed first, which next, etc., and trace the computations on the above example. Describe two different ways to avoid getting 0 as the result of evaluating 1/2.
6. Suppose that we need to send one more ship, and, correspondingly, one more captain. If the number of ships is stored in the variable ships, and the number of captains in the variable captains, which of the two lines of code leads to a correct increase in both: