This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I just started to read the "head first java book" this is the guess game code I don't want to copy the exact code from the book when running it in my IDE. I type the code in a single class, but of course when i save or compile it, the other classes should appear in the class folder as a seperate class. the 2 errors in my version of the code says;
illegal start of expression in line 50 reached end of file while parsing line 71
/*why is that? kindly check my version so that i can configure the mistake? i *already checked the open and close braces */
Originally posted by Rob Prime: Another issue: unless the random number is 0, this code will loop forever. Why? Because you never pass the guess back to the loop.
So, let the "guess" method return the number:
Then, inside the loop, assign these values to your variables:
There's another bug, with the checking against the target, but you can find that yourself
[ December 19, 2007: Message edited by: Rob Prime ]
Even if the random number becomes 0. it will never come out of the loop in the above program. There is nothing to do with random no. value to come out of the loop unless a return statement is added.
Have the determination of mirror which never fails to reflect in spite of being broken into pieces.<br /> <br />Kiss the hands you cannot bite.<br /> <br />An Optimist is one who starts taking a bath when he accidentally falls into the water.
There is a break statement which is called if any of the players has guessed right. In the erroneous code however their guesses were kept at 0, so that is why only random number 0 would lead to the break statement.