Quiz 11 Solution 1. [3 marks] Declare and instantiate a one dimensional array that can be used to store at most 6 booleans. Put the boolean value 'true' into index 4 of this array. SOLUTION: boolean[] a = new boolean[6]; a[4] = true; 2. [7 marks] Suppose you have a 2D square array that has been filled with integers. Its 'back diagonal' is the diagonal that goes from the top right corner to the bottom left corner. For instance, in the array 2 3 1 4 8 9 0 7 5 the back diagonal is made up of the numbers 1, 8, 0. Write a method that returns the sum of the back diagonal for any 2D square array which is at least 2X2. (Hint: write in the indexes for the values on the back diagonal in the example array. What do the coordinates for each value add up to?) /** * Takes a 2D square array of ints, 'a', as a parameter * and returns the sum of its back diagonal. */ public static int sumBackDiag (int[][] a) { int sum = 0; SOLUTION: for (int row = 0; row < a.length; row++) { for (int col = a[0].length - 1; col >= 0 ; col --) { if ((row + col) == (a.length - 1)) { sum += a[row][col]; } System.out.println("Row :" + row + "+ Col: " + col + " = " + sum); } } return sum; }