-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayAverage.java
More file actions
33 lines (31 loc) · 934 Bytes
/
ArrayAverage.java
File metadata and controls
33 lines (31 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Scanner;
public class ArrayAverage {
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter a size of array :-");
int n=obj.nextInt();
System.out.println("Enter a array element :- ");
int sum=array(n);
System.out.println("Sum of array is :- "+sum);
double avg=sum/n;
System.out.println("Average of array is :- " +avg);
obj.close();
}
public static int sum(int []array,int n){
int a=0;
for(int i=0;i<n;i++){
a+=array[i];
}
return a;
}
public static int array(int n){
Scanner obj=new Scanner(System.in);
int array[]=new int[n];
for(int i=0;i<n;i++){
array[i]=obj.nextInt();
}
obj.close();
int sum=sum(array, n);
return sum;
}
}