0% found this document useful (0 votes)
2 views2 pages

CSP008 Practical 01

Uploaded by

vt23cs90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

CSP008 Practical 01

Uploaded by

vt23cs90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1. Develop a java program to find the sum of odd and even numbers in an array.

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);
}
}

You might also like