File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Looping a no-good user input

 
John Melo
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 284
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe a wait() notify() situation?
 
John Melo
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you show me an example of those? I haven't really used them before.
 
Jasper Vader
Ranch Hand
Posts: 284
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic