Since you cannot take the square root of a negative number, you might use which of the following instructions to find the square root of the variable x?
a) Math.sqrt(x*x);
b) Math.sqrt((int) x);
c) Math.sqrt(Math.abs(x));
d) Math.abs(Math.sqrt(x));
e) Math.sqrt(-x);
Answer: c. Explanation: Math.abs returns the absolute value of x. If x is negative, Math.sqrt(x) causes a run-time error, but Math.sqrt(Math.abs(x)) does not since x is first converted to its positive equivalent before the square root is performed. Answer a returns x (square root of x2 is x). In answer b, casting x to an int will not resolve the problem if x is negative. In answer d, the two Math functions are performed in opposite order and so if x is negative, it still generates a run-time error. Answer e will only work if x is not positive and so if x is positive, it now generates a run-time error.