title: Counting the number of strings remaining to be read in standard input using recursion
body: <p>I want to write a method that has a Scanner parameter associated with a stream of input and counts the number of Strings within the input. However, I have a stack overflow exception. Can you tell me the reason? Thank you a lot.</p>
  
  <pre><code>import java.util.Scanner;
  public class test {
  public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      System.out.println(count(input));
  }
  
  public static int count(Scanner input) {
  
      if (input.hasNextLine())
          return 1 + count(input);
      else
          return 1;
  }
  }
  </code></pre>