import java.util.*;
class sum_of_odd_even
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
int n,a,s1=0,s2=0;
System.out.println("How many numbers input");
n=sc.nextInt();
System.out.println("Enter the numbers");
for(int i=1;i<=n;i++)
{
a=sc.nextInt();
if(a%2==0)
s1=s1+a;
else
s2=s2+a;
}
System.out.println("Sum of Even no:"+s1);
System.out.println("Sum of ODD no:"+s2);
}
}
Output:
How many numbers input
6
Enter the numbers
2
5
7
9
8
12
Sum of Even no:22
Sum of ODD no:21
class sum_of_odd_even
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
int n,a,s1=0,s2=0;
System.out.println("How many numbers input");
n=sc.nextInt();
System.out.println("Enter the numbers");
for(int i=1;i<=n;i++)
{
a=sc.nextInt();
if(a%2==0)
s1=s1+a;
else
s2=s2+a;
}
System.out.println("Sum of Even no:"+s1);
System.out.println("Sum of ODD no:"+s2);
}
}
Output:
How many numbers input
6
Enter the numbers
2
5
7
9
8
12
Sum of Even no:22
Sum of ODD no:21