0
public String toString ()
{
    String result;

    if (imaginary == 0) 
    {
        return real + " ";
    }
    else if (real == 0)
    {
        return imaginary + "i";
    }
    else (imaginary < 0);
    {
        return real + " - " + (-imaginary) + "i";
    }
    return real + " + " = imaginary + "i";
}

}

I am trying to get my code to work, to add, subtract and divide complex numbers. Everything else is compelling correctly but I have one error.

its telling me that my else (imaginary < 0); is incorrect..telling me that it is not a statement

  • You have a semicolon after that else block. This probably isn't intentional. Is that it? – APerson Nov 04 '14 at 23:47
  • 1
    The line should read `else if (imaginary < 0)` (ie, add `if` after `else`, and remove the semicolon). You cannot use a comparison on `else`. `else` means if nothing in the comparisons above was true. – worldofjr Nov 04 '14 at 23:52

1 Answers1

1

The line that gives you the error should read;

else if (imaginary < 0)

Add if after else, and remove the semicolon.

You cannot use a comparison on else. It means 'if nothing in the comparisons above was true'.

worldofjr
  • 3,868
  • 8
  • 37
  • 49
  • I tried that but even more errors occur because of that change. I didn't mean to add the semicolon at the end, thanks for catching that. But adding the if, as I said, gave me a lot more errors. From 1 error to 15. – Noelia Lobo Nov 05 '14 at 02:46
  • More errors aren't always bad. What are the new errors? – worldofjr Nov 05 '14 at 02:47