-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAverageRainFall.java
More file actions
33 lines (29 loc) · 1 KB
/
AverageRainFall.java
File metadata and controls
33 lines (29 loc) · 1 KB
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 AverageRainFall {
public static void main(String[] args) {
// Create an array of size N, which can store rainfall size for N days.
// Take rainfall measurement for N days from user and print floor of average rainfall for N days.
// Note :
// 1. Rainfall measurement is non-decimal number.
// 2. For Floor of number use Math.Floor(NUM) function.
// 3. Average = (Sum of entries) / (number of entries)
// 0 < N <= 10000
// 0<= arr[i] <= 50
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int[] T = new int[N];
for(int i=0; i<T.length; i++){
T[i] = scanner.nextInt();
}
rainFall(T);
}
public static void rainFall(int[] arr){
int sum = 0;
double avg = 0;
for(int i=0; i< arr.length; i++){
sum += arr[i];
}
avg = Math.floor(sum/ arr.length);
System.out.println((int)avg);
}
}