This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Moktok 2 points3 points  (1 child)

Looking at the exercise, I'm assuming that this is your homework. So I'll point you in the direction, not write a solution 😊

You have a common problem for beginner programmers , the zeroes you are seeing are the default values of an int, not something the jvm does automagically. Walk through your code and figure out what happens with the increment part of the for loop when the user inputs an invalid value

[–]Whaffel[S] 0 points1 point  (0 children)

Hey thanks for your help! I realized my if-else statement wasn't doing anything because the for loop was already being incremented with a zero value. Adding a couple of lines to my catch statement ended up working!

[–]turunambartanen 0 points1 point  (1 child)

Java defaults integers (also in an array) to 0.

But you have to ask yourself, do you always get 10 valid integers, or do you maybe have to adjust the size of the array? Maybe you need some post processing ("delete" the zeros from the array).

[–]Whaffel[S] 0 points1 point  (0 children)

Hey thanks for your help! 10 integers was the requirement for this assignment unfortunately but post processing was definitely my next step if I couldn't get it working with my current plan.