Skip to content

Commit 5070a0b

Browse files
committed
Create FindAverage.java
add a findAverage java file in maths directory
1 parent ee11fca commit 5070a0b

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Maths/FindAverage.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package Maths;
2+
3+
public class FindAverage {
4+
5+
//Driver
6+
public static void main(String[] args) {
7+
int[] array = {2, 4, 10};
8+
assert findAverage(array) == 5;
9+
}
10+
11+
/**
12+
* find average value of array
13+
*
14+
* @param array the array contains element and the sum does not
15+
* excess long value limit
16+
* @return average value
17+
*/
18+
public static int findAverage(int[] array) {
19+
long sum = 0;
20+
for (int i = 0 ; i < array.length; ++i) {
21+
sum += array[i];
22+
}
23+
return (int)(sum / array.length);
24+
}
25+
}

0 commit comments

Comments
 (0)