Complex implements Serializable { @Override public String toString() { StringBuilder result = new StringBuilder(); result.append("("); result.append(re); if (im < 0.0) result.append(" - ").append(-im); else if (im == 0.0) result.append(" - ").append(0.0); else result.append(" + ").append(+im); result.append("i)"); return result.toString(); } private  Complex(final double re, final double im); static Complex cart(final double re, final double im); static Complex[] difference(final Complex[] lr, final int lrlength,
	    final Complex[] rr, final int rrlength, final double epsilon); static double distance(Complex l, Complex r); static Complex[] intersection(final int lnroots,
	    final Complex[] lroots, final int rnroots, final Complex[] rroots,
	    final double epsilon); static void lejaOrder(final Complex[] xin); static Complex polar(double r, double theta); static Complex[] roots(final Complex c, final int nRoots); static Complex[] union(final Complex[] lr, final Complex[] rr); static Complex[] union(final Complex[] lr, final int lrlength,
	    final Complex[] rr, final int rrlength); static Complex[] unitRoots(final int nRoots); static Complex cart(final double re); double abs(); double absSquare(); Complex sqrt(); double arg(); Complex conj(); Complex div(final Complex c); Complex div(final double b); boolean equals(final Complex z, final double tolerance); @Override boolean equals(Object obj); double getIm(); double getRe(); @Override int hashCode(); Complex inv(); boolean isInfinity(); boolean isNaN(); Complex minus(final Complex b); Complex minus(final double z); Complex negate(); Complex plus(final Complex b); Complex plus(final double a); Complex times(final Complex b); Complex times(final double z); @Override String toString(); static final Complex I; static final Complex TWO; static final Complex ONE; static final Complex ZERO; static final Complex NEG_ONE; static final Complex NEG_TWO; static final Complex NEG_I; final static double EPS; final static double TWOPI; }
@Test public void testToString() { Assert.assertEquals("(54.654 + 7.321i)", c1.toString()); Assert.assertEquals("(77.0 - 66.12i)", c2.toString()); Assert.assertEquals("(3.14 - 0.0i)", c3.toString()); }