Pure Programmer
Blue Matrix


Cluster Map

Project: Cubic Roots (Command Line)

Cubic equations of the form Ax3 + Bx2 + Cx + D = 0 have three possible solutions given by the [[Cubic Formula]]. Write a program that accepts the four constants on the command line then prints the three possible solutions.

See: CubicRoots

Output
$ javac -Xlint CubicRootsCmdLine.java $ java -ea CubicRootsCmdLine 1 -6 11 -6 root #1: 3.0 root #2: 2.0 root #3: 0.9999999999999998 $ javac -Xlint CubicRootsCmdLine.java $ java -ea CubicRootsCmdLine 1 -2.2 -6.05 7.986 root #1: 3.3 root #2: 1.1000000000000005 root #3: -2.2

Solution