/
Solution.java
30 lines (27 loc) · 874 Bytes
/
Solution.java
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
// github.com/RodneyShag
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
int size = scan.nextInt();
int [] elements = new int[size];
int [] weights = new int[size];
for (int i = 0; i < size; i++) {
elements[i] = scan.nextInt();
}
for (int i = 0; i < size; i++) {
weights[i] = scan.nextInt();
}
scan.close();
/* Calculate weighted mean */
int total = 0;
int totalWeights = 0;
for (int i = 0; i < size; i++) {
total += elements[i] * weights[i];
totalWeights += weights[i];
}
double weightedMean = (double) total / totalWeights;
System.out.format("%.1f", weightedMean);
}
}