How to limit the user can only play the guessing game only for 5 times but it is not the user attempts on guessing in Java? -


This question is already an answer here Is:

  • 2 replies

    Here's my code :

      Package playthegame; Import java.util. *; Public class PlayTheGame {public static zero main (string [] args) {random random number = new random (); Int number togues; Int Numberoffries; Int numberoffification = 5; Int userInput; ArrayList & LT; Integer & gt; TheInputs = new ArrayList (); Scanner = new scanner (System.in); Int start = 0; Boolean Win Trekker = Wrong; Int temporary; While (0 == start) {numberToGuess = randomNumber.nextInt (10); UserInput = 0; NumberOfTries = 0; System.out.println ("Estimate number between 1 and 10:"); While (numberToGuess! = User Input & amp; NumberOffices & lt; numberOfLimit) {userInput = in.nextInt (); Temp = userInput; NumberOfTries ++; If (userInput == numberToGuess) {theInputs.add (userInput); System.out.println ("You Win! \ N"); System.out.println ("Estimate number is" + number breaks + "\ n"); System.out.println ("In" + + NumberAfteries + "is estimated \ n"); System.out.println ("These estimates are:" + in input + "\ n"); TheInputs.clear (); } And if (userInput & lt; numberToGuess) {theInputs.add (userInput); System.out.println ("Upsps, the number is too small \ n"); System.out.println ("Try Next Estimate: \ n"); } And if (userInput> number ToGuess) {theInputs.add (userInput); System.out.println ("ups, the number is too high \ n"); System.out.println ("Try Next Estimate: \ n"); }} If (numberToGuess! = UserInput) {println ("===================================== ========================= "); System.out.println ("Oppss .. you are out of the estimated range! The correct number is:" + number togius); }}}}   

    How to restrict the user, whether the user can win the game or play the game is lost only for 5 times in Java guessing game?

    To install there 5 times? Anyone, please help the user only play any possibility

    are in an endless loop with you You can only remove that loop or add

      start = 1;   

    Once the user's 5 attempts are made.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -