Lecture Notes on 20 Mar 2013 public class TestArray { // print the sum of each row in a 2-D array public static void rowSum (int[][] a) { for (int i = 0; i < a.length; i++) { int sum = 0; for (int j = 0; j < a[i].length; j++) { sum += a[i][j]; } System.out.println (sum); } } // print the sum of each column in a 2-D array public static void colSum (int[][] a) { for (int j = 0; j < a[0].length; j++) { int sum = 0; for (int i = 0; i < a.length; i++) { sum += a[i][j]; } System.out.println (sum); } } // transpose a 2-D array public static int[][] transpose (int[][] a) { int[][] b = new int[a[0].length][a.length]; for (int i = 0; i < b.length; i++) { for (int j = 0; j < b[i].length; j++) { b[i][j] = a[j][i]; } } return b; } // add two matrices together public static int[][] addMatrix (int[][] a, int[][] b) { int[][] c = new int [a.length][a[0].length]; for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { c[i][j] = a[i][j] + b[i][j]; } } return c; } // compute the dot product of two vectors public static int dotProduct (int[][] a, int[][] b) { } // find the max in a 2-D array public static int max (int[][] a) { int maxVal = a[0][0]; for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { if (a[i][j] > maxVal) maxVal = a[i][j]; } } return maxVal; } public static void main (String[] args) { } }