/** This program shows how easy it is to use a hash table in Java. */ import tio.*; import java.util.*; class HashExample2 { public static void main(String[] args) { Hashtable table = new Hashtable(); int key; String value; // build the table System.out.println("Enter some integer/string pairs. "+ "Enter 0 to end the input phase."); key = Console.in.readInt(); while (key != 0) { table.put(new Integer(key), Console.in.readWord()); key = Console.in.readInt(); } // query the table System.out.println( "Enter one of the integers entered earlier, 0 to exit."); key = Console.in.readInt(); while (key != 0) { value = (String)(table.get(new Integer(key))); System.out.println("The matching value is " + value); System.out.println( "Enter one of the integers entered earlier, 0 to exit."); key = Console.in.readInt(); } System.out.println("Printing the entire table."); Enumeration iterator = table.elements(); while(iterator.hasMoreElements()) { String temp = (String)iterator.nextElement(); System.out.println(temp); } } }