1
do {
    input = scan.nextInt();
    //calculates minimum
    if (input < min) {
        min = input;
    }
    //calculates sum of even integers
    else if (input % 2 != 1) {
        sumeven = sumeven+1;
    }       

    //calculates sum of negative integers
    if (input < 0) {
        sumnegative += input;
    }
} while (input != 0);

So the program lets the user enter a series of inputs. The problem that I'm having, is when I type a number that's less than 0. The program is supposed to tell me how many even integers there are. So the issue is when the user types a sequence that's like:

-1 -2 -45 -90 1 23 678 90 0.

The program will tell me that there's 3 even numbers. It doesn't count the negative numbers as even numbers for some reason?

Mateusz Korwel
  • 1,118
  • 1
  • 8
  • 14

1 Answers1

2

The problem is the else in else if (input%2 != 1). The else should be removed, otherwise the condition to increment the sum of evens is not reached if the input is less than min.

Raul Santelices
  • 1,030
  • 11
  • 17