Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to execute a previous step after scanning an error value?  RSS feed

 
Nabil Sayaf
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
]Hello, so i have this game iam working on for homework, which is basically the Battleship game written in java, still in the beginning and stuck at this step :




what i want is after i enter a Wrong value which is <0 or >10 the program would go back to the System.out.println("Enter the row of the ship"); step so i can retype a correct value !
sorry if my question is hard to understand iam still a newbie in java (first semester in uni)
Thanks for the help

i still cant get how to put the code so there would be line numbers next to each line, sorry
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Thank you for finding the code button, but you didn't quite use it correctly. Look here for how it works. I have corrected it for you and doesn't it look better

You can put the call to enter the number inside a loopBut that sort of code doesn't belong there. It belongs in a different method. Probably in a different class. When you try to enter the column or the orientation, you will see you are writing the same sort of code again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!