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.
Array
Summing elements of an integer array
Report a typo
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;
}
} ___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.