Question: create and test a program called Histogram.java to create a histogram of numbers entered by a user: Write a program that uses a HashMap to
create and test a program called Histogram.java to create a histogram of numbers entered by a user:
Write a program that uses a HashMap to compute a histogram of positive numbers entered by the user. The HashMaps key should be the Integer number that is entered, and the value should be an Integer counter of the number of times the key has been entered so far. Use 1 as a sentinel value to signal the end of user input.
For example, if the user inputs: 5 12 3 5 5 3 21 -1 then the program should output the following (not necessarily in this order you can use the above numbers to test your program): The number 3 occurs 2 times. The number 5 occurs 3 times. The number 12 occurs 1 times. The number 21 occurs 1 times.
Hints:
You will have to modify the program on slide 34 to read input from the keyboard rather than from the args array.
The program on slide 35 shows how to go through an ArrayList using a regular for loop. When you do that, the printed output lines contain each elements key and value.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
