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-9  เมท็อดคืนดัชนีที่เก็บค่ามากสุดในอาเรย์
  public static int maxIndex(double[] d) {  
    if (d.length == 0) throw new IllegalArgumentException("0 ช่อง");
    int maxI = 0;
    for (int i=1; i<d.length; i++) {
      if (d[i] > d[maxI]) maxI = i;
    }
    return maxI;
  }
©2009 S.Prasitjutrakul