小编Mat*_*att的帖子

如何使用在方法中的构造函数中初始化的数组?

我正在尝试定义一个用户定义的元素数量(度)的数组,然后是一个允许用户一次设置一个元素(系数)的方法.

class Polynomial 
{

    public Polynomial(int degree)
    {
        double[] coef = new double[degree];
    }

    public double[] setCoefficient(int index, double value) 
    {
        coef[index] = value; //coef was set in the constructor
        return coef;
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到了编译错误coef[index] = value;.

java arrays methods constructor

-2
推荐指数
1
解决办法
103
查看次数

标签 统计

arrays ×1

constructor ×1

java ×1

methods ×1