Skip to content

Instantly share code, notes, and snippets.

@rr-codes
Last active August 28, 2018 01:20
Show Gist options
  • Save rr-codes/72613d9678a6feeb3fbb116e88c70029 to your computer and use it in GitHub Desktop.
Save rr-codes/72613d9678a6feeb3fbb116e88c70029 to your computer and use it in GitHub Desktop.
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
float sum = 0;
int i = 0;
Map<Integer, Integer> map = new HashMap<>();
for (int num = 0; num >= 0;) {
num = sc.nextInt();
Integer value = map.get(num);
map.put(num, (value == null) ? 1 : value + 1);
int freq = map.get(num);
if (freq > 1) {
sum += num * freq;
i += freq;
}
}
if (i == 0) System.out.println("Unqe");
else System.out.printf("%.2f", sum/i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment