title: How to track the total number of attempts made by the user to input data
body: <p>I have made a very simple guessing game. But I want to count the sum of attempts a user made before finding the original number. That means once the Hidden number is matched with user input, it should tell how many numbers has been entered before the user won.</p>
  
  <p>This is my code:</p>
  
  <pre><code>package guessinggame;
  
  import java.util.Scanner;
  
  public class GuessingGame {
  
      public static void main(String[] args) {
  
          int hiddenNum = 10;
  
          Scanner input = new Scanner(System.in);
  
  
          while (true) {
              System.out.println("Enter a numebr by guessing: ");
  
              int guessedNum = input.nextInt();
  
  
              if (guessedNum == hiddenNum) {
                  System.out.println("Congratulation! Your number is matched");
  
                  System.exit(0);
  
              } else if (guessedNum &lt; hiddenNum) {
                  System.out.println("Not matched! Try a bigger number");
  
  
              } else if (guessedNum &gt; hiddenNum) {
                  System.out.println("Not matched! Try a smaller number");
  
              }    
          } 
      }    
  }
  </code></pre>