CSP008 Practical 01
CSP008 Practical 01
import java.util.Scanner;
public class SumOddEven
{
public static void main(String[] args)
{
int n, sumeven = 0, sumodd = 0;
Scanner s = new Scanner(System.in);
System.out.print("Enter the number of elements in array:");
n = s.nextInt();
int[] a = new int[n];
System.out.println("Enter the elements of the array:");
for(int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
for(int i = 0; i < n; i++)
{
if(a[i] % 2 == 0)
{
sumeven = sumeven + a[i];
}
else
{
sumodd = sumodd + a[i];
}
}
System.out.println("Sum of Even Numbers:"+sumeven);
System.out.println("Sum of Odd Numbers:"+sumodd);
}
}