Question: Write a program that reads the integers between 1 and 100 and counts the occurrences of each. Assume the input ends with 0. For example:

Write a program that reads the integers between 1 and 100 and counts the occurrences of each. Assume the input ends with 0. For example: Input is : 1 2 1 4 3 2 0 The occurrence of 1 is 2 The occurrence of 2 is 2 The occurrence of 3 is 1 The occurrence of 4 is 1 I have already started to write out the program: Scanner input = new Scanner(System.in); int [] occ = new int [100]; int num; num = input.nextInt(); while ( num > 0) { occ[ num - 1 ]++; num = input.nextInt(); } Please finish the program. We use Java 8 and Eclipse. Make sure the program runs correctly. Test the program by running the example given above. Please attach a screenshot of this. Thanks!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!