I'm having an issue when trying to count the number of even integers.
This is the code I'm working with:
int input=0, numeven=0;
Scanner scan = new Scanner(System.in);
input = scan.nextInt();
while (input != 0)
{
//calculates the total number of even integers
if (input%2 != 1)
{
numeven = numeven+1;
}
}
I don't know how to set up the while loop: while (input! = 0)
Given the test input 6, 4, -2, 0
it says that I have three even numbers, but the expected outcome is 4 (because 0
is even).