-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsumarray.java
More file actions
31 lines (26 loc) · 753 Bytes
/
Copy pathsumarray.java
File metadata and controls
31 lines (26 loc) · 753 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
import java.util.*;
class sumarray
{
public static void main(String args[])
{
int n;
Scanner sc=new Scanner(System.in);
System.out.println("enter the number of elements");
n=sc.nextInt();//number of elements
int a[]=new int[n];
System.out.println("enter the array elements");
for(int i=0;i<n;i++)
a[i]=sc.nextInt();//storing elements in array
int sume=0;//sum of even
int sumo=0;//sum of odd
for(int i=0;i<n;i++)
{
if(a[i]%2==0)
sume=sume+a[i];
else
sumo=sumo+a[i];
}
System.out.println("sum of even elements in the entered array:"+sume);
System.out.println("sum of odd elements in the entered array:"+sumo);
}
}