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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started