title: JAVA: Hashmap scanner input lookup
body: <p>Im trying to create a classthat will store a table of people's first names and ages, and read people and ages from the console (e.g. Bob 19) and add to the HashMap. After a list of name, age pairs, a name will be entered without an age (e.g. Bob) and the user will terminate their input (ctrl-z).  Print out the age of the person entered last, or print "unknown" if an age hasnt been entered for them. so for example if i entered "mary 12, bob 10, jon 20, bob" it should return 10. </p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Scanner;
  
  public class Hashmap {
      public static void main(final String[] args) {
          HashMap&lt;String, Integer&gt; names = new HashMap&lt;String, Integer&gt;();
          ArrayList&lt;String&gt; nameArray = new ArrayList&lt;String&gt;();
          Scanner in = new Scanner(System.in);
          while (in.hasNext()) {
              String name = in.next();
              nameArray.add(name);
              Integer age = in.nextInt();
              names.put(name, age);
          }
          Integer value;
          int x = nameArray.size(); 
          value = names.get(x);  
          System.out.println("the age is:" + value); 
  
      } 
  }
  </code></pre>
  
  <p>thanks for the help. I am a Java beginner and appreciate it all</p>