gpt4 book ai didi

java - 可能是类型转换问题 - Java

转载 作者:行者123 更新时间:2023-11-29 09:40:03 25 4
gpt4 key购买 nike

我写了下面的代码:

public class Point2
{
private double _radius , _alpha;

public Point2 ( int x , int y )
{
//if one or more of the point values is <0 , the constructor will state a zero value.
if (x < 0)
{
x = 0;
}

if (y < 0)
{
y = 0;
}
_radius = Math.sqrt ( Math.pow(x,2) + Math.pow (y,2) ) ;
_alpha = Math.toDegrees( Math.atan ((double)y/x) );
}

public Point2 (Point2 other) // copy constructor
{
this._radius = other._radius ;
this._alpha = other._alpha ;
}

public int getX()
{
return (int) Math.round ( Math.sin(_alpha)*_radius );
}

public int getY()
{
return (int) Math.round ( Math.cos(_alpha)*_radius );
}

public void setX (int x)
{
if (x >=0 )
{
_radius = Math.sqrt ( Math.pow (x,2) + Math.pow(getY(),2) );
_alpha = Math.toDegree ( Math.atan ((double)getY()/x));
}
}
}

问题是编译器给我一个错误:_alpha = Math.toDegrees( Math.atan ((double)y/x) ); 它说:“*找不到符号 - 方法 toDegree(double) ; 也许你的意思是:toDegrees(double)* "

似乎是什么问题?

谢谢!

最佳答案

阅读您的代码!

    _radius = Math.sqrt ( Math.pow (x,2) + Math.pow(getY(),2) );
_alpha = Math.toDegree ( Math.atan ((double)getY()/x));

那一行写的是 Math.toDegree 而不是 toDegrees!

关于java - 可能是类型转换问题 - Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5767011/

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