Q:

Write a Java program to calculate the average value of array elements

belongs to collection: Array Programs in Java with Examples

0

Write a Java program to calculate the average value of array elements

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..

public class Javaexcercise {
public static void main(String[] args) {   
 
       int[] numbers = new int[]{10, 20, 30, 60, 80, 100};       
       int sum = 0;
       for(int i=0; i < numbers.length ; i++)
        sum = sum + numbers[i];
       //calculate average value
        double avg = sum / numbers.length;
        System.out.println("Average value of the array elements is : " + avg); 
   }
}

Result:

Average value of the array elements is : 50.0

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Array Programs in Java with Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a Java program to test if an array contains ... >>
<< Write a Java program to find the index of an array...