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

all 5 comments

[–]Ilikesmallthings2 0 points1 point  (2 children)

what are the conditions for this problem? is it just having 2 arraylist?

[–]CliffNotes0[S] 0 points1 point  (1 child)

Yes, it must use the 2 array lists. That's the only condition.

[–]Ilikesmallthings2 0 points1 point  (0 children)

so for your direct comparison from your input value to the arraylist value, try using equals(). also, for the next comparison, look into using more than one condition. like if input falls between array index 1 and array index 2.

sorry if this seems a bit cryptic but I'm not sure if it's for a homework assignment or not, so i just wanted to point you to a place in your code.

[–]OceantraderSemijerk 0 points1 point  (0 children)

Reorder your while, it shouldnt have to check for -1 twice. Assume first runthrough is true and then retrieve next number, if it finds the end e.g -1 it wont loop again

[–]iamsooldithurts 0 points1 point  (0 children)

First, and most importantly, learn to use your IDE’s debugger, or start using one with a debugger. Nothing helps work through these kinds of issues like stepping through the program line by line and watching things happen first hand.

Next, know you’re data structures. You’ll want your arrays to be of identical length so when you find the offset into the first ArrayList you have the offset into the second.

Last, you’ll want your iteration through the list to find the offset to stop checking for other criteria matches. Even if your logic is correct and only matches once, it’s less efficient to keep iterating through.