我在使用Math.cos函数计算Java中的cosinus 90时遇到了一些问题:
public class calc{
private double x;
private double y;
public calc(double x,double y){
this.x=x;
this.y=y;
}
public void print(double theta){
x = x*Math.cos(theta);
y = y*Math.sin(theta);
System.out.println("cos 90 : "+x);
System.out.println("sin 90 : "+y);
}
public static void main(String[]args){
calc p = new calc(3,4);
p.print(Math.toRadians(90));
}
Run Code Online (Sandbox Code Playgroud)
}
当我计算cos90或cos270时,它给出了我的自动值.它应该是0.我用91或271测试,给出接近0是正确的.
我应该怎么做cos 90 = 0的输出?所以,它使输出x = 0和y = 4.
感谢您的建议