Question: Design and implement a Java program (name it CountOccurrences) as follows: the main method reads from the user, into a single-dimensional array of size 10
Design and implement a Java program (name it CountOccurrences) as follows: the main method reads from the user, into a single-dimensional array of size 10 elements, a number of integers between 1 and 100. Then it passes the array to another method (name it Count) to determine and printout the occurrence of each value in the array and printout the results as shown below. Assume that the inputs end with 0 (sentinel value to stop the loop). Do not store the input value 0 into the array. The program should reject/ignore invalid inputs and continue to run. Design the main method such that it allows the user to re-run the program with different sets of inputs (as in previous assignments, using a sentinel loop). Document your code, and organize and space the outputs properly using escape characters as shown in the following sample outputs (notice time vs. times):
Entered integers between 1 and 100: 7 7 7 7 7 7 7 0
7 occurred 7 times
Entered integers between 1 and 100: 5 2 3 2 1 -20 5 17 220 3 2 1 0
5 occurred 2 times 2 occurred 3 times 3 occurred 2 times 1 occurred 2 times 17 occurred 1 time
Entered integers between 1 and 100: 5 22 35 22 11 -35 55 356 45 35 111 22 11 0
5 occurred 1 time 22 occurred 3 times 35 occurred 2 times 11 occurred 2 times 55 occurred 1 time 45 occurred 1 time
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
