WestCoast - 1 year ago 101

Java Question

I am trying to practice writing some code and I can't solve my problem here.

I keep getting for "double sideA,sideB,sideC" that the expression must be an array, but it resolved to 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));

}

so can someone please help?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

`array1`

, despite the name, is *not actually an array* as you've written the code right now. As you've written it, `array1`

is just a single number.

Instead, it should be

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

(Also, `^`

does not do what you think it does; you would need `Math.pow`

. On the other hand, you can just write `Math.hypot(array2[0] - array1[0], array2[1] - array1[1])`

.)

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**