我是 Java 的新手,刚刚玩弄了一段时间的代码。
public class ThreeVector {
private double x,y,z; // definign local variables
public ThreeVector(){} // a constructor that has no input
public ThreeVector (double va1,double va2, double va3){va1=x;va2=y;va3=z;};// creatign a constructor , so can be used for calling by a method later
// Takes 3 values
public double magnitude (){
double y1= Math.sqrt(x*x+y*y+z*z);
return y1 ; // finds the magnitude of a vector
}
public ThreeVector unitv(){
ThreeVector unitv= new ThreeVector ();
unitv.ThreeVector(x/magnitude(),y/magnitude(),z/magnitude());
}
现在这是我卡住的地方。我创建了一个对象unitV
,所以我可以调用ThreeVector
构造函数,但编译器一直说要为ThreeVector
. 不知道发生了什么...