如何强制Java抛出算术异常?
如何强制Java在除以0.0或从负双精度中提取根时抛出算术异常?代码如下:
double a = 1; // or a = 0 to test division by 0
double b = 2;
double c = 100;
double d = b*b - 4*a*c;
double x1 = (-b - Math.sqrt(d)) / 2 / a;
double x2 = (-b + Math.sqrt(d)) / 2 / a;