7. แถวลำดับ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 7-22  เมท็อดหาค่าเฉลี่ยเคลื่อนที่
  public static double[] getMovingAverage(double[] y) {
    int n = y.length;
    double[] out = new double[n];
    for (int i = 1; i <= n-2; i++) {
      out[i] = (y[i - 1] + y[i] + y[i + 1]) / 3;
    }
    out[0] = (y[0] + y[1]) / 2;
    out[n - 1] = (y[n - 2] + y[n - 1]) / 2;
    return out;
  }
©2009 S.Prasitjutrakul