/* Lecture 1, example 1: Given a two dimentional array table, compute the sum of the entries of each row and store the results in one dimentional array sum, as well as the overall total in total_sum. */ class lec1ex1 { public static void main (String [] args) { int[][] table = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; int[] sum = new int[3]; int total_sum = 0; for (int i = 0; i < table.length; i++) { sum[i] = 0; //compute the sum of all entries of a given row for (int j = 0; j < table[i].length; j++) { sum[i] = sum[i] + table[i][j]; total_sum = total_sum + table[i][j]; } System.out.println ("The sum of the entries of row " + i + " is " + sum[i]); } System.out.println ("The total sum of entries is " + total_sum); } }