Problem 2: Advanced Arrays
Task 1: Find the average cost!
Suppose we have an array containing the costs of various foods. Find the average cost of the food!
- You can use a
for
loop to go through the array! - Remember, the average of a list is the total divided by the number of items
Task 2: Sorting an array!
The cost of each item in the menu is all over the place! Help us sort the array from least to greatest.
- Think of a way to sort the array (there are many different ways to do so)!
- Look at the example!
If we are given this array below,
int[] cost = {100,90,50,60,20,1,3};
we should get the following output:
int[] sorted = {1,3,20,50,60,90,100};
Task 3: Make your own array! (optional)
Now it’s your turn! Input your own elements into the array!