我非常熟悉 Java 语法,因此决定根据我之前创建的算法创建正弦代码,将其投入使用。我知道 Math.sin 可以帮助您评估正弦,但我只是为了好玩,决定继续创建我自己的源代码。然而,60° 和 120° 之间以及 240° 和 300° 之间的角度给出了错误的答案,我不知道为什么。有人可以帮我找到错误吗?我已经尝试了一切来检测它但失败了。
import java.util.Scanner;
public class Sine {
public static void main(String[] args) {
// This code solves sine according yo the general expansion of sine
// sin x = x - x³/3! +x^5/5! - x^7/7! +...
Scanner scanner = new Scanner(System.in);
double answer = scanner.nextDouble();
scanner.close();
answer = simplify(answer);
answer = converttoradian(answer);
answer = continued(answer);
System.out.println(answer);
}
// This Makes all the angles that are more than 360
// To become less than 360 and Generates the simplified
// Angles for obtuse and reflex angles
static double simplify(double x) {
if (x >= 360) {
x = x - 360;
return simplify(x);
}
else if (x <= -360) {
x = x + 360;
return simplify(x);
}
else if (x > 90 && x <= 270) {
x = 180 - x;
return x;
}
else if (x >= 270) {
x = x - 360;
return x;
}
else if (x <= -90 && x > -270) {
x = -x - 180;
return x;
}
else if (x <= -270) {
x = x + 360;
return x;
}
else {
return x;
}
}
// Simple enough and explains itself
// Converts the angles to radian
static double converttoradian(double d) {
d *= Math.PI;
d /= 180.0;
return d;
}
qq_花开花谢_0
相关分类