Short answerEasy2 marks
Write the Java expression to find the sum of cube root of x and the absolute value of y.
Topic: Math class expressions
Previous-year question practice database
Answer
Exam answer
Math.cbrt(x) + Math.abs(y)
Explanation
Two Math methods, joined by +. Math.cbrt(x) returns the cube root directly. An equally acceptable form is Math.pow(x, 1.0/3), but note it must be written 1.0/3 and not 1/3 — integer division would make the exponent 0 and the whole expression 1.0. That is a favourite trap. Math.abs(y) returns the magnitude of y, discarding its sign. Both methods return a double, so their sum is 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()?2026Character class methods are found in the package called:2025The output of Math.max(-7, Math.min(-5, -4)) is2025Which of the following converts "25" to 25.0?2025