Java半分支错误的二次公式

问题描述 投票:0回答:1

我编写了用于在Java中查找二次公式的根的代码。但是,我得到的错误是我在第6行丢失了一个分号,即使我有一个。这是怎么回事?

public class Lab2{
   public static void main (String[] args){
    double a = 1;
    double b = 2;
    double c = 4;
    double d = (math.pow(b, 2))-(4*a*c));

    if (d < 0)
    {
        String.out.println("There are no real roots.");
     } else if (a == 0) {
        x3 = (-1)*c*b;
        String.out.println("The root is " + x3);
     } else if (a != 0) {
        x1 = (((-1)*b) + (d))/(2*a);
        x2 = (((-1)*b) - (d))/(2*a);
        String.out.println(" The roots are " + x1 + " and " + x2 + ".");
     }



  }
} 
java syntax-error formula quadratic
1个回答
1
投票
    double d = (math.pow(b, 2))-(4*a*c));

这一行有一个额外的右括号。

试试这个:

    double d = (Math.pow(b, 2))-(4*a*c);
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.