Question: Counting Integers (Java) Write a program that reads an arbitrary number of integers that are in the range 1 to 25 inclusive and counts the

Counting Integers (Java)

Write a program that reads an arbitrary number of integers that are in the range 1 to 25 inclusive and counts the number of occurrences of each integer. Indicate the end of the input by a value outside of the range. After all the input is processed, print all of the values (with the number of occurrences) that were entered 1 or more times.

You will need:

A 1D array of size 25 to keep track of the number of occurrences for each of the values 1-25

A Scanner object to read input

A loop to keep track of the integer count for each value

Tip: a while or do while loop is recommended here.

The loop is initialized and updated by reading input from the keyboard

The loop should run as long as the value entered is between 1 and 25 inclusive

For each value entered, the loop should increment the appropriate spot in the array

Example: if your array is called array, and 10 is entered then position array [9] should be incremented. (Note for every number the corresponding position is 1 less, since arrays begin at 0.)

A second loop to output the numbers entered an their counts

Tip: you can use a for loop here

You will need a nested if statement to output ONLY the numbers whose occurrences are greater than or equal to 1.

A sample of the output is shown below:

Enter integers in the range 1-25. Signal end of list with the number outside of the range. 1 23 4 5 7 6 15 19 24 23 20 19 7 5 3 1 23 4 5 7 12 0 Number Times 1 2 3 1 4 2 5 3 6 1 7 3 12 1 15 1 19 2 20 1 23 3 24 1

Picture version:

Counting Integers (Java) Write a program that reads an arbitrary number of

Counting Integers Write a program that reads an arbitrary number of integers that are in the range 1 to 25 inclusive and counts the number of occurrences of each integer. Indicate the end of the input by a value outside of the range. After all the input is processed, print all of the values (with the number of occurrences) that were entered 1 or more times. You will need 1. A 1D array of size 25 to keep track of the number of occurrences for each of the values 1-25 2. A Scanner object to read input 3. A loop to keep track of the integer count for each value Tip: a while or do while loop is recommended here. The loop is initialized and updated by reading input from the keyboard The loop should run as long as the value entered is between 1 and 25 inclusive For each value entered, the loop should increment the appropriate spot in the array o Example: if your array is called array, and 10 is entered then position array [9] should be incremented. (Note for every number the corresponding position is 1 less, since arrays begin at 0.) 4. A second loop to output the numbers entered an their counts Tip: you can use a for loop here You will need a nested if statement to output ONLY the numbers whose occurrences are greater than or equal to 1. A sample of the output is shown below: Enter integers in the range 1-25. Signal end of list with the number outside of the range 1 23457 615 19 24 23 20 19 7 5 3 1 23457 120 Number Times 12 1 15 1 19 2 20 1 Counting Integers Write a program that reads an arbitrary number of integers that are in the range 1 to 25 inclusive and counts the number of occurrences of each integer. Indicate the end of the input by a value outside of the range. After all the input is processed, print all of the values (with the number of occurrences) that were entered 1 or more times. You will need 1. A 1D array of size 25 to keep track of the number of occurrences for each of the values 1-25 2. A Scanner object to read input 3. A loop to keep track of the integer count for each value Tip: a while or do while loop is recommended here. The loop is initialized and updated by reading input from the keyboard The loop should run as long as the value entered is between 1 and 25 inclusive For each value entered, the loop should increment the appropriate spot in the array o Example: if your array is called array, and 10 is entered then position array [9] should be incremented. (Note for every number the corresponding position is 1 less, since arrays begin at 0.) 4. A second loop to output the numbers entered an their counts Tip: you can use a for loop here You will need a nested if statement to output ONLY the numbers whose occurrences are greater than or equal to 1. A sample of the output is shown below: Enter integers in the range 1-25. Signal end of list with the number outside of the range 1 23457 615 19 24 23 20 19 7 5 3 1 23457 120 Number Times 12 1 15 1 19 2 20 1

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!