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 Looping a no-good user 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 » Beginning Java
Bookmark "Looping a no-good user input" Watch "Looping a no-good user input" New topic
Author

Looping a no-good user input

John Melo
Greenhorn

Joined: Jan 19, 2003
Posts: 2
I have the user input a certain code (R, M or C).
Now if the user enters something other than those three, how would I go about looping the prompt to re-enter the code?
I was thinking something like
while (!code.equals(coder, codem, codec))
{
//ask the question
}
But that doesn't work. Any way I could do this without setting a new string for every other character?
Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
maybe a wait() notify() situation?


giddee up
John Melo
Greenhorn

Joined: Jan 19, 2003
Posts: 2
Could you show me an example of those? I haven't really used them before.
Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
I would love to show you how but currently i am studying them and i don't feel confident today to show you how my friend - maybe tomorrow!
But to be able to use wait() and notify() the object which uses them must come from a class that either extends Thread or implements Runnable, even though wait() and notify() are methods of the Object class.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Validus,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
This is probably not a situation where threads would be appropriate. A simple loop will likely get the job done. Validus, your pseudocode example would seem to demonstrate some of the appropriate logic for such a construct. Perhaps you've a simple implementation detail to correct and it will work.
If it helps any, following is a simply implemented example.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Looping a no-good user input