package kwo2002.java;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Created by kwo2002 on 2015-08-21.
*/
public class MAverage {
public List<Double> mAvg(List<Integer> nList, int m) {
if (m > nList.size()) {
throw new IllegalArgumentException();
}
List<Double> avgList = new ArrayList<>();
for (int i = m - 1; i < nList.size(); i++) {
double sum = 0.0d;
for (int j = 0; j < m; j++) {
sum += nList.get(i - j);
}
avgList.add(sum / m);
}
return avgList;
}
public static void main(String[] args) {
MAverage mAverage = new MAverage();
System.out.println(mAverage.mAvg(Arrays.asList(59, 54, 70, 60, 50, 55), 3));
}
}
회고.
생각나는대로 무식하게 먼저 풀어봄..
스칼라로 풀고 싶은데 스칼라의 자료구조를 아직 잘 몰라서 자바로 풀고있는중.