Short answerEasy2 marks
Write a Java expression for the following: square root of (b^2 - 4ac)
Topic: Math class expressions
Previous-year question practice database
Answer
Exam answer
Math.sqrt(b * b - 4 * a * c)
Explanation
Math.sqrt() takes the whole expression under the root as its single argument, so everything inside the radical sign goes inside the brackets. Write b^2 as b * b rather than Math.pow(b, 2) — shorter, and it avoids the double return type of pow(). The commonest error is bracketing: Math.sqrt(b * b) - 4 * a * c would take the root of b squared only. When a formula has a bar or a radical spanning several terms, that span becomes one pair of brackets.
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