OutputModerate2 marks
Give the output of the following: Math.sqrt(Math.max(9, 16))
Topic: Nested Math methods
Previous-year question practice database
Answer
Exam answer
4.0
Explanation
Work from the inside out. Math.max(9, 16) returns the larger value, 16. Then Math.sqrt(16) gives 4.0. The decimal point matters: Math.sqrt() always returns a double, so the answer is 4.0 and not 4. Writing 4 would lose the mark. Note also that max() with two int arguments returns an int, but the moment it is passed to sqrt() the value is widened to a double.
More from Library Classes
What is the output of the statement Math.pow(36, 6/5);?2026The output of the statement:
System.out.println(Character.toUpperCase('b') + 2); is:2026What is the type of parameter to be given for the method parseInt()?2026Write the Java expression to find the sum of cube root of x and the absolute value of y.2026Character class methods are found in the package called:2025The output of Math.max(-7, Math.min(-5, -4)) is2025