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-19  เมท็อดเลือกข้อมูลในอาเรย์ที่มีค่าเป็นบวก
  public static double[] getOnlyPositive(double[] d) {
    int n = 0;
    for(int i=0; i<d.length; i++) {
      if (d[i] > 0) n++;
    }
    double[] out = new double[n];
    int k = 0;
    for(int i=0; i<d.length; i++) {
      if (d[i] > 0) {
        out[k] = d[i];
        k++;
      }
    }
    return out;
  }
©2009 S.Prasitjutrakul