我正在用 Java 为学校工作,到目前为止,我在处理课程和他们的作业问题时遇到了一些麻烦。我对二次方程类有以下标准:
到目前为止,我有:
private static double coefA;
private static double coefB;
private static double coefC;
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Please enter the a, b and c for a Quadratic: ");
coefA = input.nextDouble();
coefB = input.nextDouble();
coefC = input.nextDouble();
double discriminant = getDiscriminant();
if (discriminant < 0)
{
System.out.println("There are no real roots.");
}
else if (discriminant == 0)
{
System.out.println("The one root is: "+getRoot1());
}
else
{
System.out.println("The first root is: "+getRoot1());
System.out.println("The second root is: "+getRoot2());
}
}
//Construct
public QuadraticEquation(double a, double b, double c)
{
coefA = a;
coefB = b;
coefC = c;
}
private static double getDiscriminant()
{
double discriminant = (coefB * coefB) - (4 * coefA * coefC);
return discriminant;
}
static double getRoot1()
{
double root1 = (-coefB + Math.sqrt(getDiscriminant()))/ 2 * coefA;
return root1;
}
static double getRoot2()
{
double root2 = (-coefB - Math.sqrt(getDiscriminant()))/ 2 * coefA;
return root2;
}
}
这个等式不起作用,我什至认为我不符合标准,但我不完全理解这本书的要求。任何人都可以提供帮助吗?
慕婉清6462132
UYOU
相关分类