Calculate Average value of Array elements - Java Language Basics

Java examples for Language Basics:Array

Description

Calculate Average value of Array elements

Demo Code

public class Main {
 
        public static void main(String[] args) {
               /*  w w w.j a v  a2s  .c  o m*/
                int[] numbers = new int[]{110,120,115,25,116,60,110};
               
                int sum = 0;
               
                for(int i=0; i < numbers.length ; i++)
                        sum = sum + numbers[i];
               
                //calculate average value
                double average = sum / numbers.length;
               
                System.out.println("Average value of array elements is : " + average);
        }
}

Result


Related Tutorials