whats wrong? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

whats wrong?

public class Program { public static void main(String[] args) { double x = square (2 , -7 , -72); System.out.println (x); } public static double square (int a , int b , int c){ return -b +- Math.sqrt (b^2 - 4 * a * c) /2; } }

16th May 2020, 10:19 AM
Yahel
Yahel - avatar
5 Respuestas
0
You just need to enclose the equation in parentheses and then divide by 2. return(-b + Math.sqrt (b*b - 4 * a * c))/2;
16th May 2020, 2:25 PM
Avinesh
Avinesh - avatar
+ 2
yahel you're welcome. Nice to know that I could help.
16th May 2020, 4:01 PM
Avinesh
Avinesh - avatar
0
yahel you have written it just like you would solve it on paper. This will not work for a couple of reasons- 1) In return, the use of +- is wrong. 2) b^2 is an XOR operation and not a power operation. 3) There will be 2 roots, so you need to store it in an array and return the array. Try making these changes and it should probably get you close to the solution.
16th May 2020, 11:16 AM
Avinesh
Avinesh - avatar
0
whats the problem now? : public class Program { public static void main(String[] args) { double x = square1 (1 , -4 , 4); double y = square2 (1 , -4 , 4); System.out.println (x); System.out.println (y); } public static double square1 (int a , int b , int c){ return -b + Math.sqrt (b*b - 4 * a * c) /2; } public static double square2 (int d , int e , int f){ return -e - Math.sqrt (e*e - 4 * d * f) /2; } }
16th May 2020, 12:56 PM
Yahel
Yahel - avatar
0
Avinesh thank you!!! its working...
16th May 2020, 2:37 PM
Yahel
Yahel - avatar