When you use nextInt()
in the first loop you're "moving" a virtual cursor over your stream and you cannot go back again.
Let's say you have an input like:
17
-15
13
Then, when you call nextInt()
for the first time, your cursor move from 17 to -15. So calling nextInt()
at each loop will necessarily cause to have null values in the second loop.
You should try to use dynamic arrays or maybe a list (which don't have a fixed size)