-3

I seem to have gotten myself into an infinite while-loop:

while(number != 0){
    if(number % 2= != 0{
    numberState[1]++;
} 
else numberState[0]++;
}

The program should be able to count the amout of even and odd numbers using arrays. when I input 0 it should stop but for some reason it doesnt eventhough the while-loop states that the input has to be different than 0. Can anyone help me with this?

CasaRol
  • 39
  • 1
  • 13
  • 5
    All code should be posted in your question as code-formatted text, not as an image. we can't compile nor run an image. Also remove all text from the question that has no bearing on the problem itself, such as your being a beginner and such. It distracts and does not help us understand the actual problem you're having. Instead tell about the problem in greater detail. – Hovercraft Full Of Eels Sep 30 '17 at 12:58
  • 2
    *Never* post code as an image. Code is text and should be posted as such. If anyone wants to run your code, you're forcing them to rewrite it from scratch. – Carcigenicate Sep 30 '17 at 12:59
  • write `int number = input.nextInt()` inside the loop. – dumbPotato21 Sep 30 '17 at 12:59
  • [Why not upload images of code on SO when asking a question?](https://meta.stackoverflow.com/q/285551) – Pshemo Sep 30 '17 at 13:00

2 Answers2

2

You need to change either the variable you check in your while condition or the variable you manipulate in the while loop.

Currently you're expecting number to change and become zero.

0

Pay attention on your while loop. After every iteration you need to initialize your number variable with new number.

Nemanja
  • 21
  • 4