title: How to test System.out.println(); by mocking
body: <p>hello I have to practice how to use Mockito can someone please tell me how do we use mock objects to test the console based output testing for example </p>
  
  <pre><code>Random rand = new Random();
  int number = 1+rand.nextInt(100);              // random number 1 to 100
  Scanner scan = new Scanner(System.in);
  
  for (int i=1; i&lt;=10; i++){                     // for loop from 1 to 10
      System.out.println(" guess "+i+ ":");``
      int guess = scan.nextInt();
      //if guess is greater than number entered 
      if(guess&gt;number)
          System.out.println("Clue: lower");
      //if guess is less than number entered 
      else if (guess&lt;number )
          System.out.println("lue: Higher");
      //if guess is equal than number entered 
      else if(guess==number) {
          System.out.println("Correct answer after only "+ i + " guesses – Excellent!");
          scan.close();
          System.exit(-1);
      }
  
  }
  
  System.out.println("you lost" + number);
  scan.close();
  </code></pre>