Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help me solve the "ANSWER" problem

 
apollo abel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, im new here, and im a new java student.
i've written a program. however, the program asks the user a question, the user needs to answer either 1 or 2. i need the program to ask the question as long as the user doesnt enter 1 or 2. so if the user enters "2365" or "addasda" it will ask the question again.
this is the main class:


This is the test class:
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by apollo abel:
...i need the program to ask the question as long as the user doesnt enter 1 or 2. so if the user enters "2365" or "addasda" it will ask the question again...

Welcome to JavaRanch!

The key is the last line (commented out) in your first piece of code...

//while(!goodInput());

You just need to fill in what you want to do while the user keeps entering bad input...

[ March 31, 2006: Message edited by: marc weber ]
 
apollo abel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm i'd like to try it. however, i found a way around it.
here is the code:
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by apollo abel:
hmmm i'd like to try it...

Hmmm... I think you should try it -- at least to demonstrate to yourself how it works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic