私は次の質問に取り組んでいます:
元のリストの現在の合計を含む新しいArrayIntListを返すメソッドrunningTotalを記述します。つまり、新しいリストのi番目の値は、元のリストの要素0からiの合計を格納する必要があります。
2番目のメソッド(return)の最後の部分で立ち往生しています。パラメータを持たないメソッド。
public class ArrayIntList {
private int[] elementData;
private int size;
}
// when client calls : test = ArrayIntList.runningTotal(test);
// the folowing method works fine
public static ArrayIntList runningTotal(ArrayIntList other) {
other.elementData[0] = other.elementData[0];
for(int i = 1; i < other.size; i++){
other.elementData[i] = other.elementData[i]+ other.elementData[i-1];
}
return other;
}
// when client calls: test = test.runningTotal();
public ArrayIntList runningTotal() {
elementData[0] = elementData[0];
for(int i = 1; i < size; i++){
elementData[i] = elementData[i]+ elementData[i-1];
}
return ??;
}