Simple Array Sum

You are given an array of integers of size N. Can you find the sum of the elements in the array?

The first line of input consists of an integer N. The next line contains N space-separated integers representing the array elements.


1 2 3 4 10 11

Output a single value equal to the sum of the elements in the array.
For the sample above you would just print 31 since 1+2+3+4+10+11=31.

import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(;
        int n = in.nextInt();
        int sum = 0;
        for(int i=0;i

Leave a Reply

Your email address will not be published. Required fields are marked *