我写了以下代码:
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));
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是编译器给我一个错误:
_alpha = Math.toDegrees( Math.atan ((double)y/x) ); 它说:"*cannot find symbol - method toDegree(double); maybe you meant: toDegrees(double)* "
什么似乎是问题?
谢谢 !
阅读你的代码!
_radius = Math.sqrt ( Math.pow (x,2) + Math.pow(getY(),2) );
_alpha = Math.toDegree ( Math.atan ((double)getY()/x));
Run Code Online (Sandbox Code Playgroud)
那条线说Math.toDegree而不是Degrees!
| 归档时间: |
|
| 查看次数: |
206 次 |
| 最近记录: |