Move index++ after calling System.out.println .
At the moment, you always output the unassigned numbers . (In Java, every element in an int array is initialized to zero).
An alternative would be to completely abandon index++; and write System.out.println(numbers[index++]); . I personally find this more clear.
source share