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-23  ตัวอย่างโปรแกรมวาดกราฟเส้นและค่าเฉลี่ยเคลื่อนที่
  public static void main(String[] args) {
    double[] x = new double[200];
    double[] y = new double[200];  
    for (int i = 0; i < x.length; i++) {
      x[i] = -10 + i * 0.1;
      for (int k = 1; k <= 4; k++) {
        y[i] += Math.sin(k*x[i]);
      }
      y[i] += Math.random(); // เพิ่มสัญญาณรบกวน 
    }
    plot(300, 200, x, y);                   // วาดเส้นที่มีสัญญาณรบกวน 
    plot(300, 200, x, getMovingAverage(y)); // วาดเส้นค่าเฉลี่ยเคลื่อนที่ 
  }  
©2009 S.Prasitjutrakul