title: Limited number of tries to a simple game?
body: <p>How would I limit the tries of a simple game to just three? I would think you would use a boolean. But not sure.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class guess {
  
      public static void main(String[] args) {
          int randomN = (int) (Math.random() * 10) + 1;
  
          Scanner input = new Scanner(System.in);
          int guess;
          System.out.println("Enter a number between 1 and 10.");
          System.out.println();
  
          do {
              System.out.print("Enter your guess: ");
              guess = input.nextInt();
  
              if (guess == randomN) {
                  System.out.println("You won!");
              } else if (guess &gt; randomN) {
                  System.out.println("Too high");
              } else if (guess &lt; randomN) {
                  System.out.println("Too low");
              } 
          } while (guess != randomN);
      }
  }
  </code></pre>