AVERAGE OF ARRAY ELEMENT WITH THE HELP OF JAVA
import java.util.Scanner;
class AverageofArray
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("enter size of Array");
int n=s.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=s.nextInt();
}
AverageofArray(arr,n);
}
public static void AverageofArray(int[] a,int size)
{ double sum=0;
double Avg;
for(int i=0;i<size;i++)
{
sum=sum+a[i];
}
Avg=(sum/size);
System.out.println("Average of Array:"+Avg+" "+sum);
}
}
Comments
Post a Comment