title: Why does this scanner not work when the data type changes?
body: <p>When this runs, something goes wrong when the data changes from int to String. I think.</p>
  
  <pre><code>package people;
  
  
  import java.util.Scanner;
  
  public class People {
  
      public static void main(String[] args) {
  
          String name;
          int age;
          String college;
          String petname;
  
          Scanner scan = new Scanner (System.in);
          System.out.println ("Enter your name:");
          name = scan.nextLine();
  
          System.out.println ("Enter your age:");
          age = scan.nextInt();
  
          System.out.println ("Enter the name of your college:");
          college = scan.nextLine();
  
          System.out.println ("Enter the name of your pet:");
          petname = scan.nextLine();
  
  
          System.out.println("Hello, my name is " + name + " and I am " + age + " years");
          System.out.println("old. I'm enjoying my time at " + college + ", though");
          System.out.println("I miss my pet " + petname + " very much!");
      }
  
  }
  </code></pre>
  
  <p>The console produces:</p>
  
  <p><strong>Enter your name:
  Tim
  Enter your age:
  12
  Enter the name of your college:
  Enter the name of your pet:</strong></p>
  
  <p>As you can see, the third and fourth scanner run together. If the input is completed, this is what happens:</p>
  
  <p><strong>Enter your name:
  Tim
  Enter your age:
  12
  Enter the name of your college:
  Enter the name of your pet:
  College
  Hello, my name is Tim and I am 12 years
  old. I'm enjoying my time at , though
  I miss my pet College very much!</strong></p>
  
  <p>There is no error when I set <strong>age</strong> to String, so I am very confused. Appreciate any explanations.</p>