I am trying to determine which number entered into a HashMap was entered the most. Then display the number and the occurrances.
this is what i have:
CODE
import java.util.*;
public class HashMap
{
public static void main(String [] args) throws InputMismatchException
{
Scanner keyboard = new Scanner(System.in);
String storage = "", YN = "Y";
int testInt, value = 0;
boolean again = false;
//Create a hash map to hold the numbers to count
Map<String, Integer> hashMap = new HashMap<String, Integer>();
do
{
try
{
System.out.print("Enter an integer: ");
testInt = keyboard.nextInt();
}
catch(InputMismatchException ex)
{
System.out.print("Enter a number that is an integer.");
testInt = keyboard.nextInt();
}
storage = storage + "." + testInt;
}while(testInt != 0);
String[]integers = storage.split("[.]");
for(int i = 0; i < integers.length; i++)
{
if(integers[i].length() >= 1)
{
if(hashMap.get(integers[i]) != null)
{
value = hashMap.get(integers[i]).intValue();
value++;
hashMap.put(integers[i], value);
}
else
hashMap.put(integers[i], 1);
}
}
//create a tree map from the hash map
Map < String, Integer > treeMap = new TreeMap < String, Integer > (hashMap);
Arrays.sort(integers);
TreeMap(SortedMap hashMap);
//display mappings
System.out.println("display integers and thier count in ascending order");
System.out.print(treeMap);
System.out.println();
System.exit(0);
}
}