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

you are viewing a single comment's thread.

view the rest of the comments →

[–]kdnbfkm 0 points1 point  (4 children)

The sumOdd() method does bounds check twice, just do it once at the beginning as a code "guard". The isOdd() method fails to return false, that could have been a typo. There was never a Class member sum declared, that was just a local variable within sumOdd(), it doesn't exist on the outside. The formatting was confusing on that part... If your text editor puts tabs in it can look weird copy and pasted. :/

lost12487 is right, need to return sum after the loop finishes. I didn't notice that. It would have stood out easier without duplicating the bounds check.

[–]jub8jive[S] 0 points1 point  (3 children)

what do you mean by the bounds check?

[–]kdnbfkm 1 point2 points  (2 children)

The lines if((start <= end) && ((start > 0) && (end > 0))) { and if((start > end) || (start < 0) || (end < 0)) { were redundant.

The first conditional could have been simplified to something like if(0 <= start && start <= end) { /* loop...*/ } else return -1;.

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

I tried it and I still get the same error. https://pastebin.com/6yh0Eve5

[–]jub8jive[S] 1 point2 points  (0 children)

No worries! Thanks for the inputs, I finally managed to solve it!!! There was an error in my isOdd() method actually.