Just a quick question, I have a scala code which finds the roots of a quadratic equation. The problem I am having is printing out multiple answers and getting answers with complex numbers.
PS: I am in the first few weeks of my Scala course so I only know the bare basics.
val a = readDouble
val b = readDouble
val c = readDouble
if(b*b-4.*a*c > 0) //I have this to deal with the negatives :( {
val root1 = (-b + math.sqrt(b*b-4.*a*c)) / (2*a)
val root2 = (-b - math.sqrt(b*b-4.*a*c)) / (2*a)
println(root1 + " " root2)
}
else
println("No root")
Thanks friend!