问题描述
如何修复这里的非法表达式开头,但我没有发现任何问题
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);
}
解决方法
试试这个。
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);
}