
import java.util.HashSet;
import java.util.Scanner;
import java.util.Iterator;

class HashSetExercise
{

	//--------------//
	//     9.1      //
	//--------------//
	public static void main( String args[] )
	{
		Scanner scanner = new Scanner(System.in);
		HashSet<Integer> set = new HashSet<Integer>();
		int choice = 3;

		do {
			System.out.println("\n1) add");
			System.out.println("2) print");
			System.out.println("3) quit");
			System.out.print("\nSelection : ");
			choice = scanner.nextInt();

			if( choice == 1 ) {		// add
				System.out.print("Enter an integer : ");
				set.add( new Integer( scanner.nextInt() ) );
			}
			else if( choice == 2 ) {	// print
				print( set );
			}

		} while ( choice != 3 );	// menu loop
	}

	public static void print( HashSet<Integer> set )
	{
		Iterator<Integer> it = set.iterator();
		while( it.hasNext() ) {
			System.out.println( it.next() );
		}
		System.out.println();
	}

	//--------------//
	//     9.2      //
	//--------------//
	public static void copyToArray( HashSet<Integer> set )
	{
		Integer a[] = new Integer[set.size()];
		Iterator<Integer> it = set.iterator();

		int index = 0;
		while( it.hasNext() ) {
			a[index++] = it.next();
		}	
	}
}

