The following question states:
"Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. After the loop terminates, it prints out, on a line by itself, the sum of all the even integers read. Declare any variables that are needed. ASSUME the availability of a variable, stdin, that references a Scanner object associated with standard input".
The answer is as follows:
int even = 0;
int i = 1;
while (i > 0){
i = stdin.nextInt();
if ((i % 2)==0 && (i > 0)){
even += i;
}
}
System.out.print(even);
Why does the int variable "i" need to be set to a numerical value for the code to work? I can't seem to figure out why.