Write a java program to store 20 numbers including positive number and find the sum of negative positive numbers, negative even number, positive odd numbers, postive even numbers
Answers
Answered by
3
importjava.util.Scanner;
class sum
{
void display();
{
Scanner sc= new Scanner( System.in);
int i, sep=0,sen=0,sop=0,son=0,n;
for ( i=1;i≤20;i++)
{
System.out.println( "Enter a number");
n=sc.nextInt();
if(n%2==0 && n<0)
{
sen=sen+n;
}
if( n%2==0 && n>0)
{
sep=sep+n;
}
if(n%2!=0 && n<0)
{
son=son+n;
}
if(n%2!=0 && n>0)
{
sop=sop+n;
}
}
System.out.println ( "Sum of negative even no.s="+sen+"\n"+"Sun of positive even no.s="+sep+"\n"+"Sum of negative odd no.s="+son+"\n"+"Sum of positive odd no.s="+sop);
}
}
Similar questions