-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path18.2 Sum Even Number In Array.java
More file actions
50 lines (39 loc) · 952 Bytes
/
18.2 Sum Even Number In Array.java
File metadata and controls
50 lines (39 loc) · 952 Bytes
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
/*
Narayana friends ask him to write a java code to find the sum of all even number which is store in one dimensional array.
if the array does not have any even number then print 0 else print the sum.
Input Format
Accept the size of array n
Enter the n number of element.
Constraints
5 < n > 50
Output Format
print the sum
Sample Input 0
5
10
15
20
35
45
Sample Output 0
30
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int []arr = new int[n];
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
int sum = 0;
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
sum += arr[i];
}
System.out.print(sum);
}
}