-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevenoddarray
67 lines (39 loc) · 1.15 KB
/
evenoddarray
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
56
57
58
59
60
61
62
63
64
65
66
67
package revaturedaythree;
//by Haley Moses
import java.util.Scanner;
public class arraysumoddeven
{
public static void main (String[]args)
{
{
//find all even numbers and put in new array
// and all odd numbers and put in new array
int n;
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);
System.out.print("Enter no. of elements you want in array: ");
n = s.nextInt();
int[] a = new int[n];
System.out.println("Enter all the elements: ");
for (int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
{
int sumeven = 0; int sumodd = 0;
int i = 0;
for (i=0; i<n; i++)
{
if( a[i] % 2 == 0 )
{
sumeven = sumeven +a[i];
}
else
sumodd = sumodd +a[i];
}
System.out.println("Sum of the odd numbers array elements is: "+sumodd);
System.out.println("Sum of the even numbers array elements is: "+sumeven);
}
}
}
}