Hack: Create method that sets all elements in array to n

void setArray(int[] arr, int n) {
    // your code here
    for (int i = 0; i < arr.length; i++) {
        arr[i] = n;
    }
}

int[] array = new int[10];
setArray(array, 10);

for (int i = 0; i<array.length; i++) {
    System.out.println(array[i]);
}

// Should print all 10s when working properly
10
10
10
10
10
10
10
10
10
10

Hack: Write an array to find the average of an array

//Example finding the max in an array. 

//Finds the maximum in an array
public static double average(int[] array) {
    int count = 0;
   for (int i = 0; i < array.length; i++) {
       count += array[i];
   }
   return (double) count / (array.length);
}

//tester array
int[] test = {3, 5, 7, 2, 10};

//returns 10
System.out.println(average(test));
5.4

Hack: Find the average number of a diagonal in a 2d array

For example, here find the average of the bolded #s
1 2 3 4
5 6 7 8
9 1 2 3

public static double averageDiagonal (int[][] array2D) {
    // your code here
    int sum = 0;
    for (int r = 0; r < array2D.length; r++) {
        sum += array2D[r][r];
    }
    return (double) sum / array2D.length;
}

int[][] arr = {
    {1,2,3,4,5,6},
    {7,8,9,10,11,12},
    {0,1,2,3,4,5},
    {10,11,12,13,14,15},
    {15,16,17,18,19,20}
};

System.out.println(averageDiagonal(arr));
8.6