FRom hackerrank
Calculate and print the sum of the elements in an array, keeping in mind that some of those integers may be quite large.
Solution in Java -
import java.util.*;
public class Solution {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long c = 0l;
long arr[] = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
c = c + arr[i];
}
System.out.println(c);
}
}
Post a Comment