a) Write a static method arraySum that calculates and returns the sum of the entries in a specified

one-dimensional array. The following example shows an array arr1 and the value returned by a call to arraySum.

class DiverseArray{
    public static int arraySum(int[] array){
        int sum = 0;
        for(int i = 0; i < array.length; i++){
            sum = sum + array[i];
        }
        return sum;
    }
    public static void main(String[] args){
        int[] fram = {1,3,4,5,6};
        int x= arraySum(fram);
        System.out.print(x);
    }
}
DiverseArray.main(null);
19

Write a static method rowSums that calculates the sums of each of the rows in a given twodimensional array and returns these sums in a one-dimensional array. The method has one parameter, a twodimensional array arr2D of int values. The array is in row-major order: arr2D[r][c] is the entry at row r and column c. The method returns a one-dimensional array with one entry for each row of arr2D such that each entry is the sum of the corresponding row in arr2D. As a reminder, each row of a two-dimensional array is a one-dimensional array.For example, if mat1 is the array represented by the following table, the call rowSums(mat1) returns the array {16, 32, 28, 20}.

class DiverseArray2{
    public static int arraySum(int[] array){
        int sum = 0;
        for(int i = 0; i < array.length; i++){
            sum = sum + array[i];
        }
        return sum;
    }
    public static int[] rowSums(int[][] array){
        int[] sum = new int[array.length];
        for(int g = 0; g < array.length; g++){
            int sum1 = arraySum(array[g]);
            sum[g] = (sum1);
        }
        return sum;
    }
    public static void main(String[] args){
        int[][] fram = new int[][] {
            {1,2,3},
            {1,2,3,4},
            {3,2,1,0}
        };
        int[] x = rowSums(fram);
        for(int j = 0;j < x.length; j++){
            System.out.print(x[j] + ", ");
        }
    }
}
DiverseArray2.main(null);
6, 10, 6, 

c) A two-dimensional array is diverse if no two of its rows have entries that sum to the same value. In the following examples, the array mat1 is diverse because each row sum is different, but the array mat2 is not diverse because the first and last rows have the same sum

class DiverseArray3{
    public static int arraySum(int[] array){
        int sum = 0;
        for(int i = 0; i < array.length; i++){
            sum = sum + array[i];
        }
        return sum;
    }
    public static int[] rowSums(int[][] array){
        int[] sum = new int[array.length];
        for(int g = 0; g < array.length; g++){
            int sum1 = arraySum(array[g]);
            sum[g] = (sum1);
        }
        return sum;
    }
    public static boolean isDiverse(int[][] arr2d){
        boolean isDiverse = true;
        int[] cheese = rowSums(arr2d);
        for (int i = 0; i < cheese.length; i++) {
            int burger = cheese[i];
            for (int j = i + 1; j < cheese.length; j++) {
                if (burger == cheese[j]) {
                    isDiverse = false;
                }
            }
        }
        return isDiverse;
    }
    public static void main(String[] args){
        int[][] fram = new int[][] {
            {1,2,3},
            {1,2,3},
            {3,2,1,0}
        };
        System.out.println("is " + isDiverse(fram));
        int[][] fram2 = new int[][] {
            {1,2,3},
            {1,2,3,4,5},
            {5,5,5,5}
        };
        System.out.println("is " + isDiverse(fram2));
    }
}
DiverseArray3.main(null);
is false
is true