Consider the following statement. What is printed?
System.out.println(Math.sqrt(49));
77.04949.0Math.sqrt returns a double, so the square root of 49 is printed as 7.0 rather than 7.
Explanation
The method returns the nonnegative square root of a nonnegative argument as a double. Even when the root is mathematically a whole number, the returned value keeps its decimal form, and printing it shows that form.
- A is not correct:
7is the whole-number form of the answer, butMath.sqrtreturns adouble, so the printed value carries a decimal point. - C is not correct:
49is the argument passed into the call, not the value the call returns; the method returns the square root of that argument. - D is not correct:
49.0is the argument written in decimal form, but the call returns the square root of49, which is7.0.