We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ee11fca commit 5070a0bCopy full SHA for 5070a0b
1 file changed
Maths/FindAverage.java
@@ -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