[ Write a Program to input 10 numbers into an integer array and display the sum of even and odd number separately.
Program Code :
import java.util.*;
class Sum_of_Odd_Even
{
public static void main(String args[])
{
int i,so=0,se=0;
int n[]=new int[10];
Scanner sc=new Scanner(System.in);
//Accepting 10 Array Element
for (i=0;i<10;i++)
{
System.out.print("Enter the Array Element = ");
n[i]=sc.nextInt();
}
for (i=0;i<10;i++)
{
if(n[i]%2==0) //Checking Even or Odd Number
se=se+n[i]; //Sum of Even Number
else
so=so+n[i]; //Sum of Odd Number
}
System.out.println("Sum of Even Array Elements = "+se);
System.out.println("Sum of Odd Array Elements = "+so);
}
}
No comments