我目前有:
public double[] differences()
{
diffs = new doublae[sequence.length-1];
for (int = 0; i<sequence.length; ++i){
double diff = sequence[i+1] - sequence[i];
diffs[i] = diff;
}
return diffs;
}
但是,当我运行测试程序来检查它时,这不起作用。
答案 0 :(得分:1)
您的范围应该不同 - i
不应该通过sequence.length - 2
,以使i+1
成为有效的索引。
double[] diffs = new double[sequence.length-1];
for (int = 0; i < sequence.length - 1; i++) { // changed the condition
double diff = sequence[i+1] - sequence[i];
diffs[i] = diff;
}