0

I wrote code for finding the roots of a quadratic formula in Java. However, I get the error that I'm missing a semi-colon in line 6, even though I have one there. What's going on?

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 + ".");
     }



  }
} 
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
bob
  • 21
  • 1

1 Answers1

1
    double d = (math.pow(b, 2))-(4*a*c));

This line has an extra closing parenthesis.

Try this:

    double d = (Math.pow(b, 2))-(4*a*c);
Tarun
  • 986
  • 6
  • 19
darkpbj
  • 2,892
  • 4
  • 22
  • 32