You are given an array of integers of size . You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large.
Input Format
The first line of the input consists of an integer . The next line contains space-separated integers contained in the array.
Output Format
Print a single value equal to the sum of the elements in the array.
Constraints
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static long aVeryBigSum(int n, long[] ar) { // Complete this function int count = 0; long result = 0; while(count < n) { result += ar[count]; count++; } return result; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); long[] ar = new long[n]; for(int ar_i = 0; ar_i < n; ar_i++){ ar[ar_i] = in.nextLong(); } long result = aVeryBigSum(n, ar); System.out.println(result); } }
'Programming > >> Algorithm' 카테고리의 다른 글
[Lucky Algorithm] Plus Minus (0) | 2017.10.03 |
---|---|
[Lucky Algorithm] Diagonal Difference (0) | 2017.10.03 |
[Lucky Algorithm] Compare the Triplets (0) | 2017.10.03 |
[Lucky Algorithm] Simple Array Sum (0) | 2017.10.03 |
[Lucky Algorithm] Mini-Max Sum (0) | 2017.10.03 |
댓글