Computer Science, asked by tsohan, 5 months ago

write a program in Java to print the sum of nagative,sum of positive odd number and sum of positive even number from a list of number entered by the user the list terminates when the user enters a zero.​

Answers

Answered by ThunderGirl
0

Answer:

import java.util.Scanner;

class example

{

public static void main(String args[])

{

Scanner in=new Scanner(System.in);

int number,negative=0,positive_even=0,positive_odd=0;

while(true)

{

System.out.print("Enter number : ");

number=in.nextInt();

if(number>0)

{

if(number%2==0)

{

positive_even=positive_even+number;

}

else

{

positive_odd=positive_odd+number;

}

}

else if(number<0)

{

negative=negative+number;

}

else

{

break;

}

}

System.out.println("Sum of negative numbers : "+negative);

System.out.println("Sum of positive even numbers : "+positive_even);

System.out.println("Sum of positive odd numbers : "+positive_odd);

}

}

Similar questions