Using Only Part of an Array

The goal for this exercise To build on the knowledge of arrays that you've developed so far, by applying it to a (slightly) new problem: filling some (but not all) the elements of an array and then correctly using only those filled slots

What you need to do to prepare for this exercise:


What you need to do for this exercise

Implement the Using_Part_Of_An_Array,.RunExercise() method. This method must start by creating an array of 10 integers.

Next, the method will allow the user to enter anywhere from 0 to 10 integers. Each of these numbers must be stored in the array, starting with the zeroth slot in the array, and working your way up as the user enters more numbers.

If you want, you may assume that the user will only enter positive integers as valid input, and that they will enter a negative integer as a sentinel to indicate that they are finished entering data. If you prefer to use a different means of figuring out how many numbers the user wants to enter, feel free to use that, instead..

Finally, the method must calculate the sum and average of the integers entered by the user. Make sure that you don't include any of the slots that are 'empty' (i.e., that don't contain any user input)

Hint: You will need to declare an integer variable whose purpose is to store the number of integers entered by the user.

Warning: If you run past the edge of the array (or try to access a negative indexed element) you'll see an IndexOutOfBoundsException, which your hint that you've gone beyond the bounds of the array.

What you need to do for this exercise: In the starter project, add code to the the Using_Part_Of_An_Array class, so that the RunExercise method does the following:

  1. Create an array

  2. Fill the array with up to 10 numbers based on user input, as described above.

  3. Calculate the sum and average of the numbers that the user entered.