Respuesta :
Answer:
import java.util.Scanner;
public class num15 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int sumEven =0;
int sumOdds =0;
int countEven =0;
int countOdd =0;
System.out.println("Enter numbers");
int num = in.nextInt();
if(num%2==0){
sumEven = num;
countEven++;
}
else{
sumOdds =num;
countOdd++;
}
while(num>0){
System.out.println("Enter another number: ");
num = in.nextInt();
if(num%2==0){
sumEven= sumEven+num;
countEven++;
}
else{
sumOdds = sumOdds+num;
countOdd++;
}
}
System.out.println("Sum of Odds "+sumOdds);
System.out.println("Sum of Evens "+sumEven);
System.out.println("Count Odds "+countOdd);
System.out.println("Count Evens "+(countEven-1));
}
}
Explanation:
The complete program in Java is given above
Using the scanner class the user is repetitively prompted to enter a number
The while(num>0) loop ensures that only positive numbers greater than 0 are entered, when 0 or a negative number is entered the loop terminates.
Within the while loop an if/else statement is used to keep track of the sumEvens, countEvens, sumOdds and countOdds
The values of these variables are printed on separate line
See code output attached.
![Ver imagen ijeggs](https://us-static.z-dn.net/files/d82/63785489ef16422cab3761ee415c289e.png)