posted 12 years ago
Supposing I assigned variables a,b, and c to the coefficients in the quadratic formula:
(b +/ sqrt(b^24ac))/2a
How would I write that in Java? In my actual program I have assigned a as variable "coa", b as "cob", and c as "cob". Here is what I have tried without success:
When compiling, I get errors mainly saying that I cannot use a particular operator with a double variable.
(b +/ sqrt(b^24ac))/2a
How would I write that in Java? In my actual program I have assigned a as variable "coa", b as "cob", and c as "cob". Here is what I have tried without success:
When compiling, I get errors mainly saying that I cannot use a particular operator with a double variable.
posted 12 years ago
1) Use "Math.sqrt()", not just "sqrt()".
2) Java doesn't have a builtin exponentiation operator  you have to use the Math.pow() function.
Otherwise things are fine (assuming coa, cob, coc are of type "double".)
2) Java doesn't have a builtin exponentiation operator  you have to use the Math.pow() function.
Otherwise things are fine (assuming coa, cob, coc are of type "double".)
posted 12 years ago
For future reference, it will help a lot if you copyandpaste the exact error message here. I would guess that the particular operator you are referring to is the ^. In Java, this is not an exponent operator as it is in other languages. As EFH says, you need to use Math.pow() instead. Notice that you need to specify the class name when you use a static method from another class (such as the Math class).
Layne
Layne
I'm full of tinier men! And a tiny ad:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
