posted 22 years ago
Welcome to Java Ranch, "S!"
This is clearly a homework problem, but I'll bite, anyway. Here's a nice, straightforward algorithm:
Use any implementation of the java.util.Map interface. Create Integer objects to be both the keys and the values. The keys would be the numbers in the array, the values would be the counts. To add a number to the map, you would fetch the key; if it's not there, add it with a value of 1. If it is there, get the value, add one, replace it.
At the end, get an iterator over the Map keys, and you'll get a list of the numbers that appeared; you can then fetch the count for each from the Map. Hint: one particular choice of Map implementation would be better than any others, because it would assure that in this step, you'd fetch the keys in order.