Summing elements of an integer array

Report a typo

Given a list of integer data, you're tasked with summing the elements of the list and returning the sum. Fill the blanks in the Java code to create a method 'arraySum' that accepts an integer array 'arrayToSum' and returns the sum of all the elements. Also, fill the gaps to call this method in the main function with a created list of integers from 1 to 5.

Fill in the gaps with the relevant elements
public class Main {
    public static void main(String[] args) {
        int[] integerArray =  int[]{1, 2, 3, 4, 5};
        System.out.println(arraySum(integerArray));
    }
    private static int arraySum(int[] arrayToSum) {
        int sum = 0;
         (int number : arrayToSum) {
            sum += number;
        }
         sum;
    }
}
fornewreturn
___

Create a free account to access the full topic