title: 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?
body: <p>Here is my code:</p>
  
  <pre><code> package playthegame;
  
  
  import java.util.*;
  public class PlayTheGame {
  public static void main(String[] args) {
  
       Random randomNumber = new Random();
      int numberToGuess;
      int numberOfTries;
      int numberOfLimit = 5;
      int userInput;
  
      ArrayList&lt;Integer&gt; theInputs = new ArrayList();
      Scanner in = new Scanner(System.in);
      int start = 0;
      boolean winTracker = false;
      int temp;
  
      while (0 == start) {
          numberToGuess = randomNumber.nextInt(10);
          userInput = 0;
          numberOfTries = 0;
          System.out.println("Please guess the number between 1 and 10: ");
          while (numberToGuess != userInput &amp;&amp; numberOfTries &lt; numberOfLimit) {
  
              userInput = in.nextInt();
              temp = userInput;
              numberOfTries++;
  
              if (userInput == numberToGuess) {
                  theInputs.add(userInput);
                  System.out.println("You win!\n");
                  System.out.println("The guess number is " + numberToGuess+"\n");
                  System.out.println("It takes a total of " + numberOfTries + " guesses\n");
                  System.out.println("These are the guesses number : " + theInputs+"\n");
                  theInputs.clear();
              } else if (userInput &lt; numberToGuess) {
                  theInputs.add(userInput);
                  System.out.println("Oppss, The number is too small\n");
                  System.out.println("Try next guess: \n");
              } else if (userInput &gt; numberToGuess) {
                  theInputs.add(userInput);
                  System.out.println("Oppss, The number is too High\n");
                  System.out.println("Try next guess: \n");
              }
          }
  
          if (numberToGuess != userInput) {
              System.out.println("==============================================================");
              System.out.println("Oppss..You are out of Guess Limitation!The correct number is: " + numberToGuess);
          }
  
      }
  
  
  
  }
  
  }
  </code></pre>
  
  <p>How to limit the user can only play the guessing game only for 5 times in Java if the user whether have won or lost playing the game? </p>
  
  <p>is there any possibility to set the user only play for 5 times?anyone, please help</p>