title: HiLo Game With Random Number Generator
body: <p>i have one real quick question about this HiLo game. When I go and test it everything works properly except when I want it to display how many tries it took them to guess. What I'm trying to say is it doesn't count the initial guess, but counts the ones after it so it shows one less guess than what it actually is. Here is my code.</p>
  
  <p>EDIT:I have another quick question. I want the program not to count the guess if it is out of range from 0 to 10. How would i go about doing so because when I run the program it counts the guess as one of my tries.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import java.util.Random;     // Random number generator class
  import java.util.Scanner;    // reads user inputs
  
  public class HiLo
  {
   public static void main (String[] args)
   {
    //declare variables
    final int MAX = 10;
    int answer, guess;
    int numberOfTries = 0 ;
    String again;
  
    Scanner Keyboard = new Scanner(System.in);
  
    do
  
    {
     System.out.print (" I'm thinking of a number between 0 and "
     + MAX + ". Guess what it is: ");
     guess = Keyboard.nextInt();
     //guess
     Random generator = new Random(); //Random  number generator. 0 to 10.
     answer = generator.nextInt(MAX) +1;
  
     if (guess &gt; 10)//if guess is bigger than 10 then error message
     {
     System.out.println ("ERROR – Your guess is out of the range 0 to 10.");
     }
     if (guess &lt; 0)//if guess is smaller than 0 then error message
     {
        System.out.println ("ERROR – Your guess is out of the range 0 to 10.");
     }
  
     while (guess != answer )//If guess is not the answer
     {
  
     if (guess &gt; answer )//If guess is more than the answer
     {
     System.out.println ("You guessed too high! \nTry again:");
     guess = Keyboard.nextInt();
     }
  
     if (guess &lt; answer )//If guess is less than the answer
     {
     System.out.println ("Too Low! \nTry again:");
     guess = Keyboard.nextInt();
     }
  
     numberOfTries=numberOfTries+1;
  
     }//end of the loop
  
     // display result
     if ( guess == answer)
     {
     numberOfTries += 1;
     System.out.println ("YOU WIN!");
     System.out.println("It took you " + numberOfTries + " tries!") ;
     System.out.println();
     System.out.print( "Do you want to play again(Y/N)?");
     }
  
  
     Keyboard.nextLine(); // skip over enter key
     again = Keyboard.nextLine();
  
     numberOfTries=0;
  
  
  
    }while (again.equalsIgnoreCase ("Y") );
  
  
  
   } // end of class
  
  } //end of main</code></pre>
  </div>
  </div>
  </p>
  
  <p>Thank you!</p>