-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraySumAvg.java
More file actions
33 lines (24 loc) · 858 Bytes
/
Copy pathArraySumAvg.java
File metadata and controls
33 lines (24 loc) · 858 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
public class ArraySumAvg {
public static void main(String[] args) {
System.out.println("Welcome to SUma and Avg: ");
int[] numArray = ArrayUtility.inputArray();
long sum = sum(numArray);
double avg = avg(numArray);
System.out.println("Sum of the numbers is: " +sum);
System.out.println("Average of the numbers is: " +avg);
}
public static long sum(int[] numArray){
long sum = 0;
int i = 0;
while(i < numArray.length){
sum = sum + numArray[i];
i++;
}
return sum;
}
public static double avg(int[] numArray){//before double there is long for which we type cast the long nto int
double sum = sum(numArray);
return (sum/numArray.length);
// return (int) (sum/numArray.length);
}
}