‫Hello my friends, and welcome to coding Exercise number ten.
‫I want from you to write a program to calculate the average value of array elements.
‫Post the video and think about how to solve this exercise.
‫I'm waiting your solutions, guys.
‫Please comment them below in order to help you understanding where is your your error or where is your
‫mistake.
‫So I am waiting your solutions in the comments below.
‫I hope you solve it well and correctly.
‫I'm waiting your solutions in the comment below in order to help you.
‫If there is any mistake and arrays number equal to new int array and I will enter the numbers.
‫1257898.
‫Okay.
‫I need to get this average of these numbers.
‫I need the average.
‫But I want to mention this very important note.
‫The average is equal to the sum of these numbers and elements over the numbers of these.
‫The counter of this number.
‫So one plus two plus five plus seven plus nine plus eight over six because we have six elements here.
‫Calculate the sum of all elements in order to get the sum.
‫I will create an array variable equal to sum and for loop that loops through all the elements of this
‫array and add them up.
‫So I less than numbers dot length are plus plus.
‫The sum would be equal to the old sum plus numbers at index.
‫What I can make plus equal numbers.
‫I can write this.
‫The same way.
‫Now let's calculate the average.
‫Calculate
‫the average value double since I need to make an average, an average may be a resulting in float sum
‫over that numbers dot length.
‫Here I am dividing the sum of all the elements over the number of animals
‫system that out dot print.
‫The average
‫is.
‫Plus average.
‫Let's run the program and see.
‫And here we go.
‫The average is 5.0.
‫Let me check if this correct calculator, one plus two plus five plus seven plus nine plus eight over
‫six, it will give me 5.3, not five.
‫So I need to cast this to a double.
‫So here, double.
‫I'm casting it to double.
‫On the problem with coverage.
‫And here we go.
‫The average is 5.3.
‫So guys always pay attention to casting the typecasting, especially between novels, floats and numbers.