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.
Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingClasses and objectsClasses and members
Instance methods
Completing a method to sum array elements
Report a typo
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;
}
} ___
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.