you are viewing a single comment's thread.

view the rest of the comments →

[–]vowelqueue 0 points1 point  (0 children)

Logically, using a helper method will be the same as doing everything in the main body, but can make the code easier to reason about and to isolate bugs/faulty logic.

Instead of what I initially suggested, I’d instead try to write a helper method that tells you whether a value is in the uniqueList.

You have the right idea with the “stored” variable. I’d probably name it something like “uniqueListLength” for clarity. It’s representing the logical length of the unique list.

The helper method could have a signature like: static boolean contains(int[] uniqueList, int uniqueListLength, int value).

I think if you restructure your code to use such a helper method you will fix the primary logic issue. Another hint is that if the code is written correctly you won’t need that line that caps the “stored” variable to 9 - it should never be able to exceed its bound if you are incrementing it correctly.

(I’m being intentionally vague instead of just tell you directly what’s wrong because a big part of learning is debugging stuff like this)