【发布时间】:2011-09-18 23:08:23
【问题描述】:
我有一个方法,它接收一个字符串数组并根据长度找到每几个项目的平均值。我想要根据偏移量的值删除数组中前几项的方法。
public static double[] getMovingAverage(String[] priceList, int length, int offset){
double[] newPriceList = convert(priceList);
int listLength = newPriceList.length;
int counter = 0;
double listsum;
double[] movingAverage = new double[listLength];
try{
for (int aa = 0; aa < listLength-1; aa++){
listsum = 0;
for (int bb = 0; bb < length; bb++){
counter = aa+bb;
listsum = listsum + newPriceList[counter];
}
movingAverage[aa] = listsum / length;
}
if (offset>0){
//remove first #offset# elements
}
}catch(Exception e){
System.out.println(e);
}
return movingAverage;
}
*注意:转换();将 String[] 转换为 double[]
【问题讨论】:
标签: java arrays string arraylist boolean