OutputHard2 marks
What are the values stored in variables r1 and r2: (i) double r1 = Math.abs(Math.min(-2.83, -5.83)); (ii) double r2 = Math.sqrt(Math.floor(16.3));
Topic: Nested Math methods
Previous-year question practice database
Answer
Exam answer
(i) r1 = 5.83 (ii) r2 = 4.0
Explanation
Work from the inside out in both cases. (i) Math.min(-2.83, -5.83) returns the SMALLER value. With negatives that is -5.83, since it lies further left on the number line — this is the trap. Then Math.abs(-5.83) strips the sign, giving 5.83. (ii) Math.floor(16.3) rounds DOWN to 16.0, and Math.sqrt(16.0) is 4.0. Both answers keep the decimal point, since every one of these methods returns 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