Need help with java algorithm

This is the algo code
This is the problem statement
14 Replies
JavaBot
JavaBot2mo ago
This post has been reserved for your question.
Hey @arch__user! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
arch__user
arch__userOP2mo ago
No description
arch__user
arch__userOP2mo ago
can anyone clear my doubt ?
dan1st
dan1st2mo ago
What is the issue with it?
arch__user
arch__userOP2mo ago
For example lets say user guess is 3 and we have an array where startup location is placed at [2,3,4] the first time` the userguess (3) is not equals to 2 and hence the outer else block will be executed which will return miss ? Even though 3 is present in the second element of the array ? at first iteration when 3 != 2 return miss will be executed which is wrong because 3 will be equals to 3 in the seccond iteration Isn't the algo wrong ?
dan1st
dan1st2mo ago
yeah I think that part should be outside of the REPEAT (and doesn't need an ELSE)
No description
arch__user
arch__userOP2mo ago
setlocation cells is the setter method btw
arch__user
arch__userOP2mo ago
shouldn't it be like this ?
No description
dan1st
dan1st2mo ago
Isn't that what I just said? after the repeat
arch__user
arch__userOP2mo ago
yes. Kinda hard for me to believe there are mistakes in the head first java book so weird
dan1st
dan1st2mo ago
I haven't read it maybe you have an old version of it?
arch__user
arch__userOP2mo ago
I have the latest one 3rd edition
arch__user
arch__userOP2mo ago
Actually this was the extract I was reading from the book. I made it shorter so that you don't have to read to much :-
No description
No description
No description
No description
JavaBot
JavaBot2mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?