Lecture Notes on 22 Mar 2013 public class TestArray { 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); } } 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); } } 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; } 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; } public static int dotProduct (int[][] a, int[][] b) { int sum = 0; for (int i = 0; i < a.length; i++) { sum += a[i] * b[i]; } return sum; } public static int[][] mult (int[][] a, int[][] b) { int[][] c = new int [a.length][b[0].length]; for (int i = 0; i < c.length; i++) { for (int j = 0; j < c[i].length; j++) { int sum = 0; for (int k = 0; k < b.length; k++) { sum += a[i][k] * b[k][j]; } c[i][j] = sum; } } return c; } 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) { } }