title: Exception in thread "main" java.util.InputMismatchException at nextInt, next
body: <p>This error has come up when I try to run this:</p>
  
  <pre><code>public class gift1 {
      public static void main(String[] args) throws IOException{
  
  
          //declare and initialize scanner to read from gift1.in
          Scanner scan = new Scanner(new File("gift1.in"));
          //declare and initialize PW to write result
          PrintWriter out = new PrintWriter(new File("gift1.out"));
  
          int np = scan.nextInt();
          List&lt;String&gt; people = new ArrayList&lt;String&gt;();
          for(int o = 1; o&lt;np; o++)
          {
              people.add(scan.next());
          }
          Map&lt;String, Integer&gt; monReceived = new HashMap&lt;String, Integer&gt;();
          for(String person : people)
          {
              monReceived.put(person, 0);
          }
          Map&lt;String, Integer&gt; Initial = new HashMap&lt;String, Integer&gt;();
          for(int i = 0; i &lt; np; i++)
          {
              String person = scan.next();
              int amount = scan.nextInt();
              int giveto = scan.nextInt();
  
              Initial.put(person, amount);
  
              int amountGift = 0;
              if(giveto &gt; 0)
              {
                  amountGift = (amount/giveto);
                  monReceived.put(person, monReceived.get(person) + (amountGift%giveto));
              }
  
              for(int j = 0; j &lt; giveto; j++)
              {
                  String receivers = scan.next();
                  monReceived.put(receivers, monReceived.get(receivers) + (amountGift - amountGift%giveto));
  
              }
          }
          for(String person : people)
          {
              out.println(person + " " + (monReceived.get(person) - Initial.get(person)));
          }
          out.close();
          System.exit(0);
      }
  }
  </code></pre>
  
  <p>do you know why this is? Do i need to add a try/catch? that is the only thought I have had. I have considered changing and using a BufferedReader but that reduces functionality that I need. What is the problem with my code? Thanks, Sam.</p>
  
  <p>More details:</p>
  
  <p>It says the errors are at:</p>
  
  <pre><code>at java.util.Scanner.throwFor(Scanner.java:909)
      at java.util.Scanner.next(Scanner.java:1530)
      at java.util.Scanner.nextInt(Scanner.java:2160)
      at java.util.Scanner.nextInt(Scanner.java:2119)
      at gift1.main(gift1.java:24)
  </code></pre>
  
  <p>so I assume it is to do with the scanner but I can't see a problem hence I thought I should try try/catch but it hasn't worked as Ive done it.`</p>
  
  <p>edit:the input data is shown below: the first line is an int so I don't understand the error.</p>
  
  <pre><code>   10 
      mitnik 
      Poulsen 
      Tanner 
      Stallman 
      Ritchie 
      Baran 
      Spafford 
      Farmer 
      Venema 
      Linus 
      mitnik 
      300 3 
      Poulsen 
      Tanner 
      Baran 
      Poulsen 
      1000 1 
      Tanner 
      Spafford 
      2000 9 
      mitnik 
      Poulsen 
      Tanner 
      Stallman 
      Ritchie 
      Baran 
      Farmer 
      Venema 
      Linus 
      Tanner 
  </code></pre>