-1

The array in the main method looks like this:

double[] x = { 11.11, 66.66, 88.88, 33.33, 55.55 };

And the code that's giving me trouble is:

public static double computeAverage(double[] x){

        double xTotal = 0.0;

        for (int i = 0; i < x.length(); i++)
        {
            xTotal = xTotal + x[i]; 
        }
        double computeAverage = xTotal / x.length();
        return computeAverage;
}

About the only thing I know for sure is that I'm trying to get the length of the array x and it's giving me an error because it's a double and not an integer. Does the "double" has an equivalent to "length" I can try?

4

1 回答 1

4

length()不是任何数组类的方法。相反,您应该通过length字段获取长度。不带参数访问字段(即不带括号)。

for (int i = 0; i < x.length; i++)
{
于 2012-07-14T00:05:37.973 回答