The following Java code gives the average.
- public class Avg {
- public static void main(String[] args) {
-
- int[] array = new int[] {
- 30, 80, 65, 95, 06, 60, 1
- };
-
- int sum = 0;
- for (int i = 0; i < array.length; i++)
- sum = sum + array[i];
-
- double average = sum / array.length;
- System.out.println("Average value of an array elements is : " + average);
- }
- }
Thank you, keep learning and sharing.