Completing a method to sum array elements

Report a typo

You are working with an incomplete code in Java which calculates and prints the sum of an integer array. In the main method, it creates an instance of the class, defines an integer array, and then calls an instance method which computes the sum of the elements of this array. You will need to fill in the blanks to complete the function declaration in the main method, the instance method call and the return statement of the 'arraySum' method.

Fill in the gaps with the relevant elements
 Main {
    public static (String[] args) {
        Main main = new Main();
        int[] array = {1, 2, 3, 4, 5};
        System.out.println(main.(array));
    }

    int arraySum(int[] array) {
        int sum = 0;
        for (int i : array) {
            sum += i;
        }
         sum;
    }
}
arraySumreturnpublic classvoid main
___

Create a free account to access the full topic