 <pre><code>public class GuessingGame { public static void main(String[] args) { int NumberGuess = 0; Random randomNumber = new Random(); int randomInt = randomNumber.nextInt(51); System.out.println("Guess the number between 0 -50:"); int i = 1; Scanner UserGuess = new Scanner(System.in); while (i &lt;= 7) { NumberGuess = UserGuess.nextInt(); if (NumberGuess == randomInt) { System.out.println("Correct! You win!"); System.out.println("It took you " + i + " guesses."); System.exit(0); } else if (NumberGuess &lt; 0 || NumberGuess &gt; 50) { System.out.println("Invalid Input, please enter numbers between 0 and 50"); } else if (NumberGuess &lt; randomInt) { System.out.println("Guess is too small."); } else if (NumberGuess &gt; randomInt) { System.out.println("Guess is too big."); } System.out.println("You have made " + i + " guesses out of 7"); i++; } System.out.println("Game over!"); System.out.println("All 7 Guesses used!"); System.exit(0); } } </code></pre> <p>Also you should not <code>Scanner UserGuess = new Scanner(System.in);</code> use this statement inside the loop. <strong>Only one copy of the scanner should be created, outside the loop.</strong></p>