The objective of this exercise is to compute the average value of the integer values stored in an array.
You have to fill the body of the method average()
which takes as parameter the array of integers of which it computes and returns the average value. Please note that this method must return an integer.
To compute the average value of an integer, it is necessary to traverse the whole array and to compute the sum of all its values (so you will need a variable to store this temporary result), then you have to divide this sum by the size of the array.
In Java, you can get the size of an array myarray
by consulting its
length
attribute (in other words,
myarray.length
). Notice that there is no parenthesis
after length
.
In python, retrieving the size of an array myarray
is as easy as calling len(myarray)
.