Assignment 

Instructions: 

The assignment is to write a loop that counts the number of even numbers, finds the sum of all even numbers, counts the number of odd numbers, and finds the sum of the odd numbers, then displays them all on 1 line seperated by a space. The loop needs to terminate when a negative number is entered. I have until Halloween to get this done. Right now, Pearson, the website I have to submit this to, is saying that there is no output for this. For this assignment, Pearson does not want me to declare a class or a public static void main.

intnum = 0;
intevenSum = 0;
intoddSum = 0;
intevenCount = 0;
intoddCount = 0;

while (num>= 0) {
num = stdin.nextInt();

if ((num % 2) == 0 &&num>= 0){
evenSum += num;
evenCount++;
}

else if ((num % 2) != 0 &&num>= 0) {
oddSum += num;
oddCount++;
}
}

System.out.print(evenSum + ” ” + oddSum + ” ” + evenCount + ” ” + oddCount); 

Solution 

Scanner stdin = new Scanner(System.in);

intevenSum = 0;

intoddSum = 0;

intevenCount = 0;

intoddCount = 0;

intnum = stdin.nextInt();

while (num> 0) {

if (num % 2 == 0) {

evenSum += num;

evenCount++;

} else {

oddSum += num;

oddCount++;

}

num = stdin.nextInt();

}

System.out.println(evenSum + ” ” + oddSum + ” ” + evenCount + ” ” + oddCount);