2016-11-10 92 views
0

我正在嘗試編寫一些代碼,並且我無法在這裏解決我的問題。 我不斷收到「double sideA,sideB,sideC」表達式必須是數組,但它解析爲double。表達式必須是一個數組,但是......要加倍

public static double Calculate (double array1, double array2, double array3) { 

      double sideA = Math.sqrt(((array2[0]-array3[0])^2)+((array2[1]-array3[1])^2)+((array2[2]-array3[2])^2)); 
      double a= Math.abs(sideA); 
      double sideB = Math.sqrt(((array1[0]-array3[0])^2)+((array1[1]-array3[1])^2)+((array1[2]-array3[2])^2)); 
      double b= Math.abs(sideB); 
      double sideC = Math.sqrt(((array2[0]-array1[0])^2)+((array2[1]-array1[1])^2)+((array2[2]-array1[2])^2)); 
      double c= Math.abs(sideC); 
      double s = ((0.5) * (a + b + c)); 
      return Math.sqrt(s * (s - a) * (s - b) * (s - c)); 
    } 

所以有人可以幫忙嗎?

+0

哎,我編輯了這篇文章。問題是它一直告訴我它應該是一個數組(對於double sideA,sideB,sideC),但它解析爲double。我想得到一個雙倍,所以我如何解決這個問題? – WestCoast

+0

公共靜態雙計算(雙[]數組1,雙[]數組2,雙[] ARRAY3){ – MikeJRamsey56

+0

可能的重複[類型表達的必須是一個數組類型,但它解析爲INT](HTTP://計算器。 com/questions/9155423/the-type-of-the-expression-must-an-an-array-type-but-it-resolved-to-int) – WestCoast

回答

2

array1,儘管名稱是,實際上並不是數組,因爲您已經編寫了代碼。正如你所寫,array1只是一個單一的數字。

相反,它應該是

public static double calculate(double[] array1, double[] array2, double[] array3) { 

(另外,^不會做你認爲它。你需要Math.pow在另一方面,你可以只寫Math.hypot(array2[0] - array1[0], array2[1] - array1[1])。)

相關問題