Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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);
Comment

PREVIOUS NEXT
Code Example
Java :: Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8. 
Java :: calling a void method java 
Java :: Java Handlers(Appenders) 
Java :: Load array of strings from console 
Java :: how to et curent directory in java 
Java :: eclipse versioning .classpath 
Java :: Java try...finally block 
Java :: Print Positives of array 
Java :: java stream dristinct 
Java :: add checkbox box rows in tabulator 
Java :: Algorithms - sum 
Java :: method object class in android 
Java :: varstatus foreach jsp 
Java :: square oot of 154 
Java :: Note: flutterpluginspathproviderPathProviderPlugin.java uses unchecked or unsafe operations. 
Java :: android java string animations 
Java :: sealed class java codegrepper 
Java :: polymorphism array with abstract class java 
Java :: jframe centerlaized 
Java :: ejercicios de clases abstractas e interfaces en java 
Java :: what does .set do in java 
Java :: setlist arraylist java swing example 
Java :: radio button lambda javafx 
Java :: setvisibility not working in fragment 
Java :: DMC5 performace mod 
Java :: Switch statement expressions jdk12+ 
Java :: signed and unsigned data types in java 
Java :: java netbeans one column enabled 
Java :: compile option in android 
Java :: dynamic fib 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =