gpt4 book ai didi

java - 我收到 java.lang.ArithmeticException 错误

转载 作者:行者123 更新时间:2023-12-01 18:43:21 25 4
gpt4 key购买 nike

这是在 main 方法内部。尝试计算 double x 数学公式,这给我运行代码带来了问题。有人可以帮忙吗?

final int P = Integer.parseInt(args[0]);
final int Q = Integer.parseInt(args[1]);
final double H = Double.parseDouble(args[2]);
final int N = Spiro.numberOfRevolutions(P, Q);

IPoint2D point = new IPoint2D(0., 0.);
SimpleDrawing.drawPoint(point);

for (int i = 1; i <= 360*N; i++) {
final int r = P/Q;
double radianI = Math.toRadians(i);
double x = ((1 - r) * Math.cos(radianI)) + (H * Math.cos(((1- r) / r) * radianI));
double y = ((1 - r) * Math.sin(radianI)) + (H * Math.sin(((1- r) / r) * radianI));

IPoint2D point1 = new IPoint2D(x,y);
SimpleDrawing.drawPoint(point1);
}

最佳答案

如果P小于Q(或者Q0)将立即抛出ArithmeticException )

final int r = P/Q;

r 的值为 0。然后除以 r=0

double x = ((1 - r) * Math.cos(radianI)) + (H * Math.cos(((1- r) / r) *  radianI));

抛出ArithmeticException

关于java - 我收到 java.lang.ArithmeticException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18993326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com