(String[] args)
| 7 | |
| 8 | public class Statistics { |
| 9 | public static void main(String[] args) { |
| 10 | Random rand = new Random(47); |
| 11 | Map<Integer, Integer> m = new HashMap<>(); |
| 12 | for(int i = 0; i < 10000; i++) { |
| 13 | // Produce a number between 0 and 20: |
| 14 | int r = rand.nextInt(20); |
| 15 | Integer freq = m.get(r); // [1] |
| 16 | m.put(r, freq == null ? 1 : freq + 1); |
| 17 | } |
| 18 | System.out.println(m); |
| 19 | } |
| 20 | } |
| 21 | /* Output: |
| 22 | {0=481, 1=502, 2=489, 3=508, 4=481, 5=503, 6=519, |