title: Java using Scanner as a parameter for a constructor
body: <p>This is a question for a school assignment, which is why I am doing it in such a way.</p>
  
  <p>Anyways, I make a scanner using Stdin in the main method (Scanner stdin = new Scanner(System.in); is the line), reading data from a txt specified when the program is run. This Scanner works as expected in the main, however I need to use it in an custom class that has Scanner as an argument:</p>
  
  <pre><code>    public PhDCandidate(Scanner stdin)
      { 
  
      name = stdin.nextLine();
      System.out.println(name); //THIS NEVER RUNS
      preliminaryExams = new Exam[getNumberOfExams()];
  
      for(int i = 0; i &lt;= getNumberOfExams(); i++)
      {
          preliminaryExams[i] = new Exam(stdin.nextLine(), stdin.nextDouble());
      }
      System.out.print("alfkj");
     }
  </code></pre>
  
  <p>At this point any call of the Scanner will just end the program, with no exceptions or errors thrown. Only calling .next() works. I could make the program work, but it would be hacky, and I really don't understand what is happening. I suspect I am missing a very simple concept, but I'm lost. Any help would be appreciated.</p>