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; } }
5 ответов
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;
+ 2
yahel you're welcome.
Nice to know that I could help.
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.
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;
}
}
0
Avinesh thank you!!! its working...