-
Notifications
You must be signed in to change notification settings - Fork 0
/
sum_of_array.java
42 lines (35 loc) · 978 Bytes
/
sum_of_array.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//{ Driver Code Starts
// Initial Template for Java
import java.io.*;
import java.util.*;
class Main {
// Driver code
public static void main(String[] args) throws Exception {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine().trim());
while (t-- > 0) {
int n = Integer.parseInt(br.readLine().trim());
String[] str = br.readLine().trim().split(" ");
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(str[i]);
}
int ans = new Solution().sum(arr, n);
System.out.println(ans);
}
}
}
// } Driver Code Ends
// User function Template for Java
class Solution {
int sum(int arr[], int n) {
// code here
int s=0;
for(int i=0;i<n;i++)
{
s=s+arr[i];
}
return s;
}
}