Answers for "get the average of an array in java"

0

get the average of an array in java

double[] array = {19, 12, 16, 200, 13}; //Array
double total = 0; //Initialising total variable
double average = 0; //Initialising average variable

for(int i=0; i<array.length; i++){ // Looping through to retrieve total value
  total += array[i];
}

average = total / array.length; // Dividing the total by the length of the array OR number of numbers to get the average.

System.out.println("The average is: " + average);
Posted by: Guest on March-13-2022

Code answers related to "get the average of an array in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language