The sum of array elements

Report a typo

Write a program that calculates the sum of the elements of an array of ints.

Input data format

The first line contains the size of an array.

The second line contains elements of the array separated by spaces.


Output data format

The sum of the input array elements.

Note that If your solution gets the code quality warning "System.arraycopy is more efficient", please simply ignore it in respect of this code challenge.

Sample Input 1:

3
1 2 3

Sample Output 1:

6

Sample Input 2:

5
-1 0 1 2 -2

Sample Output 2:

0
Write a program in Java 17
class Main {
public static void main(String[] args) {
// put your code here
}
}
___

Create a free account to access the full topic