-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraySumAverage.java
More file actions
41 lines (23 loc) · 856 Bytes
/
Copy pathArraySumAverage.java
File metadata and controls
41 lines (23 loc) · 856 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
34
35
36
37
38
39
40
41
public class ArraySumAverage {
public static void main(String[] args) {
System.out.print("Welcome to Sum and Average Calculator using Array:\n" );
int[] myArr1 = ArraytoUtility.inputArray();
double Sum = SumOfArray(myArr1);
double Avg = AverageOfArray(myArr1);
System.out.println("The sum of the given number is: "+Sum);
System.out.println("The average of the given number is: "+Avg);
}
public static double SumOfArray(int[] myArr1){
int sum = 0 ;//Accumulator of sum of numbers
int i = 0;
while(i < myArr1.length){
sum += myArr1[i];
i++;
}
return sum;
}
public static double AverageOfArray(int[] myArr1){
double Avg = SumOfArray(myArr1)/myArr1.length ;
return Avg;
}
}