Count U.S. states by the first letters of their names. For example, there are eight states whose names begin with 'N'.
In USStates.java, you're provided with a string array with 50
elements, the names of the 50 U.S. states. Your task is to implement
countStatesByFirstLetter()
. This method uses the STATE_NAMES
array and
constructs a map whose keys are the 26 capital letters of the alphabet, and
whose values are the numbers of states with that first letter.
We've provided a simple test main()
for you; feel free to add additional logic
to further test your code. Do not modify the definition of STATE_NAMES
.
Your code must compute the number of states whose names start with each letter. Do not simply hard code the results.