USER STORY
Create a program that calculates the average of the elements of a list
EXPECTED OUTCOME
The average of the elements of the list is 6.
SOLUTION
List<Integer> myList = new List<Integer>{5,1,9,11,2,4,7,9};
Integer sum = 0;
for(Integer i=0; i<myList.size(); i++){
sum += myList.get(i);
}
Decimal average = sum / (Decimal)myList.size(); // typecast to Decimal to get a decimal average
System.debug('The average of the elements of the list is ' + average);
Video
Video does not exists.