Computer Science, asked by SGhidryhjnhg, 9 months ago

You want to calculate the sum of all positive even numbers and sum of
all negative odd numbers from a set of numbers. You can enter 0 (zero)
to quit the program and thus it displays the result. Write a program to
perform the above task.​

Answers

Answered by prashantrohilla32
16

ANSWER :   import java.util.*;

public class Main

{

public static void main(String[] args) {

   Scanner sc=new Scanner(System.in);

 int num=1;

 

 int oddsum=0;

 int evensum=0;

 

 while(num!=0)

 {    

     int a=sc.nextInt();

     num=a;

     if(num==0)

     {

         break;

     }

     

     if(a%2==0)

     {   if(a>0)

         evensum+=a;

     }

     

     if(a%2!=0)

     {    if(a<0)

         oddsum+=a;

     }

     

   

 }

 

 System.out.println("Sum of even numbers = "+evensum);

 System.out.println("Sum of odd numbers = "+oddsum);

 

}

}

Attachments:
Answered by shivanisiri31
6

Answer:

The answer is written in the above TB...Hope it helps

Pls mark me as brainlist

Attachments:
Similar questions