File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Narayana friends ask him to write a java code to find the sum of all even number which is store in one dimensional array.
3
+ if the array does not have any even number then print 0 else print the sum.
4
+
5
+ Input Format
6
+
7
+ Accept the size of array n
8
+ Enter the n number of element.
9
+
10
+ Constraints
11
+
12
+ 5 < n > 50
13
+
14
+ Output Format
15
+
16
+ print the sum
17
+
18
+ Sample Input 0
19
+
20
+ 5
21
+ 10
22
+ 15
23
+ 20
24
+ 35
25
+ 45
26
+ Sample Output 0
27
+
28
+ 30
29
+ */
30
+ import java .io .*;
31
+ import java .util .*;
32
+
33
+ public class Solution {
34
+
35
+ public static void main (String [] args ) {
36
+ /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
37
+ Scanner sc = new Scanner (System .in );
38
+ int n = sc .nextInt ();
39
+ int []arr = new int [n ];
40
+ for (int i =0 ;i <n ;i ++)
41
+ arr [i ]=sc .nextInt ();
42
+ int sum = 0 ;
43
+ for (int i =0 ;i <n ;i ++)
44
+ {
45
+ if (arr [i ]%2 ==0 )
46
+ sum += arr [i ];
47
+ }
48
+ System .out .print (sum );
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments