• Post Reply Bookmark Topic Watch Topic
  • New Topic

question about ifs  RSS feed

 
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could it be that possible ?or is mistake?(i mean to use inside if the '' do-while'')
 
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error message do you get? What is the smallest possible example you can create that shows this problem?
 
Greenhorn
Posts: 26
1
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ekte,

I was examining your code and I think only a "while" loop should be used because the user's first entry could be "escape". If you use a do{}while(x) the thing inside will be executed at least once without checking for escape. I see that the user makes a choice, either 1,2 or 3 and then actions occur until they type "escape". I would check for "escape" first in case they want to exit without executing code, like the case where they choose the wrong menu item.



I looked for "UserInput" in the Java SE 8 API but I did not see it listed between UserException and UserPrincipal. Is this another class you created? Maybe consider utilizing the built-in Scanner class to collect user keystrokes.


Sources

1. Java SE 8 API, https://docs.oracle.com/javase/8/docs/api/
 
Saloon Keeper
Posts: 3333
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of taking the user input as an int, why not take it in as a String? Then you can check it against "escape", and if it's not "escape" convert the String to an int and proceed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!