How to add the “play again?” feature for java

后端 未结 3 1308
生来不讨喜
生来不讨喜 2021-01-24 17:01

Im making a guessing game for my class and I need some help for adding a \"play again\" feature at the end of the game when you\'ve guessed the right number:

pub         


        
3条回答
  •  失恋的感觉
    2021-01-24 17:58

    There are a lot of options I can think about. The quickest:

    -- place all the code between lines int numtoguesses = rand.nextInt(1000) + 1; (inclusive) and end of main method inside an infinite loop
    -- at the end of your current code block, add an interogation to the user, asking him whether he/she wants to play again (you can define a convention for the pressed keys); this part is placed also inside the infinite loop
    -- if he/she doesn't want to, break the (outer) infinite loop

提交回复
热议问题