id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

quadratic_solution


The general form of a quadratic equation is a*x^2 + b*x + c = 0.

Define a function that when passed the coefficients a, b and c and a fourth boolean attribute flag, returns,

1. null, if no solution exists (that's why the return type is Double, not double)

2. the higher of the two roots of the equation, if flag is true and solution exists.

3. the smaller of the two roots of the equation, if flag is false and solution exists. You can use the built-in Math.max, Math.min and Math.sqrt functions. NOTE: The challenge of this question is in the research and not the implementation.


quadratic_solution(1, -3, 2, true) → 2.0
quadratic_solution(1, -3, 2, false) → 1.0
quadratic_solution(1, 10, 24, true) → -4.0

...Save, Compile, Run (ctrl-enter)

Double quadratic_solution(double a, double b, double c, boolean flag) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 3 Post-solution available

Copyright Nick Parlante 2017 - privacy