-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsum_of_array_elements.java
55 lines (41 loc) · 1.11 KB
/
sum_of_array_elements.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
43
44
45
46
47
48
49
50
51
52
53
54
55
//{ Driver Code Starts
//Initial Template for Java
import java.util.*;
import java.io.*;
import java.lang.*;
class Driver
{
public static void main(String args[])throws IOException
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while(t-- > 0)
{
int n = Integer.parseInt(read.readLine());
String str[] = read.readLine().trim().split(" ");
int input[] = new int[n];
for(int i = 0; i < n; i++)
{
input[i] = Integer.parseInt(str[i]);
}
//int x = Integer.parseInt(read.readLine());
Get obj = new Get();
System.out.println(obj.sumElement(input, n));
}
}
}
// } Driver Code Ends
//User function Template for Java
class Get
{
public static int sumElement(int arr[], int n)
{
// Your code here
int sum=0;
for(int i=0;i<n;++i)
{
sum=sum+arr[i];
}
return sum;
}
}