0

So I need some help with my APCS class. We have to make a code that with a specific runner class, would tell you if the discriminate on the quadratic formula is positive or without real solutions. This is my code so far, but I keep getting the error "Error: Syntax error on token ",", invalid AssignmentOperator" This is my code

import static java.lang.Math.*;
public class Quadratic
{
 private double a,b,c;
  public Quadratic(double aa, double bb, double cc)
  {
    a=aa;
    b=bb;
    c=cc;
}
public boolean hasSolutions ()
  double calcDisc = Math.pow((b,2)-(4*a*c));
  if (CalcDisc < 0)
  {
    return false;
  }
  else
  {
    return true;
  }
}
}

The line that says "double calcDisc = Math.pow((b,2)-(4*a*c));

3 Answers3

0

I think you are trying to do b^2 - 4*a*c?

That would be Math.pow(b,2) - (4*a*c)

topched
  • 765
  • 3
  • 11
0

Math.pow(x,y) takes two parameters. But you are trying to pass in (b,2)-(4*a*c) as the argument. Since you have (b,2) in the expression, it doesn't make sense, thus the error message you are seeing.

I'm guessing what you actually want is: double calcDisc = Math.pow(b,2)-(4*a*c)

Which subtracts (4*a*c) from b^2

MysticXG
  • 1,437
  • 10
  • 10
0

I think you have one level too many parenthesis.

  double calcDisc = Math.pow((b,2)-(4*a*c));

Should be:

  double calcDisc = Math.pow(b,2)-(4*a*c);
bigtlb
  • 1,512
  • 10
  • 16