Search code examples
javacalculatorinfinity

how do i fix the illegal start of expression here


How do I fix the illegal start of expression here, i don't see anything wrong with it though

static void divide(double a, double b){
            double c = (number_a / number_b);
            String s;
            if (c == Double.POSITIVE_INFINITY || c == Double.NEGATIVE_INFINITY || c == Double.NaN)
                s = "Undefined";
            else
                s = Double.toString(c);
            System.out.println(s);
        }

Solution

  • Try this.

    static void divide(double a, double b) {
        double c = a / b;
        String s;
        if (Double.isInfinite(c) || Double.isNaN(c))
            s = "Undefined";
        else
            s = Double.toString(c);
        System.out.println(s);
    }