This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Loop for console input.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Loop for console input...." Watch "Loop for console input...." New topic
Author

Loop for console input....

Jonathan King
Greenhorn

Joined: Jan 28, 2004
Posts: 14
All right guys and gals, I've been working on this for hours now, and I am stuck!! I get a user's choice from console, and perform some actions based on that choice. After, they can enter 'y' to try another menu choice, or any key to exit the program. I have gotten to where the program runs great, and when they choose y to try again, the menu will print, and they can do another choice, but if I want to choose 'y' again, it just ends. I would like to get it to loop so if they press 'y' 1000 times after running a choice (as long as it is not the exit choice) it will print the menu again and they can choose another choise. HOW!!! PLEASE EASE MY FRAZZLED MIND!!! ARGGGHHHH!!!

THANK YOU!!!
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
Your if condition where you check if input is y is the problem. The var input is a String; Strings cannot be compared via the == operator. Look at the String documentation in the API to see what method you need to use.
I noticed that you are setting done = true outside the while loop.


Ever Existing, Ever Conscious, Ever-new Bliss
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Loop for console input....