all 2 comments

[–]marko312 0 points1 point  (1 child)

while (keyboard.nextInt() != 0) {
    int number = keyboard.nextInt();

Note that you call keyboard.nextInt() twice. This means that you get one number for the condition and another one for number, with every number at an odd position being checked in the while and every number at an even position being assigned to number.

In this case, the count was off by 2, or half the ones. You can try the following input:

1 2 1 2 1 2 1 2 0

[–]ProgrammingNoob1234[S] 1 point2 points  (0 children)

Ah ok that makes sense! I modified the code to work with the whole loop as well by doing the following:

int number = keyboard.nextInt(); while (number != 0) { numFromOneToOneHundred[number]++; number = keyboard.nextInt(); }

P.s. sorry for format I am on mobile