好吧,我想制作一个程序,可以找到二次方程的判别式以及根数。我迄今为止创建了该程序来查找判别式,但是我无法调用该方法来查找根数。有人可以向我解释这是如何完成的吗?谢谢。如何调用带参数的方法?
public class quadMethods
{
public static void main (String args[])
{
new quadMethods();
}
public quadMethods()
{
System.out.println ("The discriminant is: " + discrim (1, 6, 8));
System.out.println ("The number of roots is: " + numRoots (1, 6, 8));
}
public double discrim (double a, double b, double c)
{ //assumes ax^2+bx+c=0
//returns the discriminant of the quadratic equation
//b*b-4*a*c
//replace the return 1
double discriminant = b*b-4*a*c;
return discriminant;
}
public int numRoots (double a, double b, double c)
{ //assumes ax^2+bx+c=0
//returns the number of roots for the quadratic equation
//call discrim method, make an if to return 0, 1, or 2.
//replace the return 1
return 1;
}
}
不要编辑你的问题,有人花时间回答你。 –
对不起。我想删除这篇文章,但我似乎无法这样做。 – asdfghjkl9999
否,因为你有一个接受的答案,删除的原因是什么? –