Skip to content
← Back to Community
How do i find the average of the values in an array? IN JAVA
Profile icon
arthurabelo

Thanks

Voters
Profile icon
Moeedr01
Profile icon
arthurabelo
Comments
hotnewtop
Profile icon
XavierDD
int[] numbers = new int[]{20, 30, 25, 35, -16, 60, -100}; //calculate sum of all array elements int sum = 0; for(int i=0; i < numbers.length ; i++) sum = sum + numbers[i]; //calculate average value double average = sum / numbers.length;