OneCompiler

PRINT AVERAGE

123

***Define a class to declare an array of size 20 of double data type , accept the elements into the array and perform the following :
- Calculate and print the average of the elements.

import java.util.*;

public class average {
public static void main(String[] args) {
double avr=0, sum=0, small=0;
Scanner sc = new Scanner (System.in);
double a[] = new double[20];
System.out.println("ENTER 20 ELEMENTS");
for(int i = 0; i<20;i++)
a[i] = sc.nextDouble();
for(int i = 0; i<20; i++)
sum+= a[i];
avr = sum/20;
System.out.println("AVERAGE : " + avr);
}
}

FOR CODE ,
Click : https://onecompiler.com/java/3xywxgydw (TO FIND OUTPUT)