I have a program written two different ways, and it seems to me that the final output should be exactly the same. I was wondering if someone could help me understand why the two versions aren't "logically" the same.
Version 1 returns true regardless of what values are stored in the "nums" array. Version 2, however, works exactly as intended. The two versions seem to evaluate the same way, but this is clearly not the case. Why is that?
Keith Lynn wrote:I ran your programs and got false on both
Grrr!! I found the problem...
In my original copy of Version 1, I missed the fact that I had accidentally added a semicolon at the end of the if statement:
I've spent hours breaking down every aspect of the code and trying to understand why it wasn't working as it was supposed to. I've never run into that problem before, but it makes perfect sense why it wouldn't work the way I wanted it to.
Thank you for your help. It helped me to identify the problem and probably saved me from more hours spent looking in the wrong direction.
I've spent hours breaking down every aspect of the code and trying to understand why it wasn't working as it was supposed to.
It is strange that you posted here a different version.
There is a saying that if all else fails when trying to tame a piece of hardware or software, one should read the documentation.
Well, if all else fails, a session with a debugger can be useful in this situtation.
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
Create Edit Print & Convert PDF Using Free API with Java