在我調用getDistance(points [i],points [j])的行上,我收到錯誤,要求我將getDistance方法參數更改爲double,而不是數組,但我認爲我正在向該方法傳遞數組到多維數組如何工作。作爲地方,你把它的類型是double[]
這是不一樣的爲什麼我的數組被識別爲double?
public static void main(String[] args) {
double[][] points = {
{1.0, 2.0, 3.0},
{0.0, 0.0, 2.0},
{1.0, 1.5, 4.0},
{3.0, 2.0, 1.0}
};
for(int i=0; i<points.length; i++){
for(int j=1; j<points[0].length; j++){
getDistance(points[i], points[j]);
}
}
}
public double getDistance(Array points1[], Array points2[]){
double x1 = Array.getDouble(points1, 0);
double x2 = Array.getDouble(points2, 0);
double y1 = Array.getDouble(points1, 1);
double y2 = Array.getDouble(points2, 1);
double z1 = Array.getDouble(points1, 2);
double z2 = Array.getDouble(points2, 2);
double distance = Math.sqrt(Math.pow(x1 - x2, 2) +(Math.pow(y1 - y2, 2) +
(Math.pow(z1 - z2, 2))));
return distance;
}
什麼是'Array'在'公共雙getDistance的(陣列points1 []數組points2 [])'? – Pshemo
你的意思是什麼數組呢?我指出我將2個數組傳入方法,並且這些數組通過點[i]和點[j]傳遞,因爲點是多維數組,因此據我所知,points [i]應該通過點[0] [0到2] –
'points [i]'的類型不是'Array []'。它是'double []'(即'double'數組)。 – resueman