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-25  เมท็อดการบวกเมทริกซ์
public class Matrix {
  public static double[][] add(double[][] a, double[][] b) {
    if (a.length != b.length || a[0].length != b[0].length) {
      throw new IllegalArgumentException("มิติไม่เท่ากัน");
    }
    double[][] c = new double[a.length][a[0].length];
    for (int i = 0; i < c.length; i++) {
      for (int j = 0; j < c[0].length; j++) {
        c[i][j] = a[i][j] + b[i][j];
      }
    }
    return c;
  }
©2009 S.Prasitjutrakul