1// Java program to calculate sum of even and odd numbers in an array
2import java.util.Scanner;
3public class FindSumOf
4{
5 public static void main(String[] args)
6 {
7 int number, sumEven = 0, sumOdd = 0;
8 Scanner sc = new Scanner(System.in);
9 System.out.println("Please enter number of elements in an array: ");
10 number = sc.nextInt();
11 int[] arrNumbers = new int[number];
12 System.out.println("Please enter elements of the array: ");
13 for(int a = 0; a < number; a++)
14 {
15 arrNumbers[a] = sc.nextInt();
16 }
17 for(int a = 0; a < number; a++)
18 {
19 if(arrNumbers[a] % 2 == 0)
20 {
21 sumEven = sumEven + arrNumbers[a];
22 }
23 else
24 {
25 sumOdd = sumOdd + arrNumbers[a];
26 }
27 }
28 System.out.println("Sum of even numbers in an array: " + sumEven);
29 System.out.println("Sum of odd numbers in an array : " + sumOdd);
30 sc.close();
31 }
32}