Alright, so the problem is this:
I want to enter a bunch of numbers, a random set, of say 5 numbers. At the end of that number, I'll add a sixth number, 0, which will be a signal for my loop to end.
To achieve this, this is what I'll do.
I run my program and this is my input:
1 3 4 2 5 0
So I want the program to print
1 3 4 2 5 "End of sequence"
Here's my code that will purportedly do such a thing (all of this is in main method):
Scanner input = new Scanner(System.in);
System.out.println("Alright, what?");
boolean notZero = true;
while (notZero)
{
System.out.println(input.nextInt());
if (input.nextInt() == 0)
System.out.println("End of sequence");
notZero = false;
}
These, however, are the results I get:
https://i.sstatic.net/DUFhs.jpg
Interestingly, if I don't have the while-loop stop, and I input the same number list again (1 3 4 2 5 0) it'll output 3 and 2, which are the even numbers in my number list - and all this vexes me further.
Any ideas?