File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Java Guessing Game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Guessing Game" Watch "Java Guessing Game" New topic
Author

Java Guessing Game

Jacqueline Turof
Greenhorn

Joined: Apr 18, 2013
Posts: 12
I just started taking programming course in Java and I'm trying to write a guessing game. I would like the user to be able to start the game over again without having to restart the program. Every time I try to set up a loop to do this it never goes through the enter loop again. I'm just not constructing the loop properly, but I'm not sure how I can correct it. Any help or suggestions on how to improve my code would be appreciated. Thanks in advance!

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11308
    
  16

One thing i would suggest...use a bunch of System.out.println statements to see what is going on. If something isn't looping like you think it should, print out what you are comparing and prove that is is really equal to what you think it is. odds are it is not.

Print out your "playAgain" variable just before your line 58 and see what it is.
Print out each time you enter the top of a loop, so you know if you are looping (and how many times).
etc.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jacqueline Turof
Greenhorn

Joined: Apr 18, 2013
Posts: 12
Thanks for the fast reply and the help. I was able to fix my code and have it working now.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11308
    
  16

Excellent!!! I'ts always better when you are able to figure it out on your own.

I have been a strong champion of System.out.println() here for debugging...I'm glad it really worked for you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Guessing Game