Advertisement
IrinaIgnatova

Count Real Numbers

Jul 16th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.util.*;
  5. import java.util.stream.Collectors;
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.         Scanner scanner = new Scanner(System.in);
  12.  
  13. //        double [] numbers=Arrays.stream(scanner.nextLine().split(" "))
  14. //                .mapToDouble(Double::parseDouble)
  15. //                .toArray();
  16.  
  17.         List<Double> nums = Arrays.stream(scanner.nextLine().split(" "))
  18.                 .map(Double::parseDouble)
  19.                 .collect(Collectors.toList());
  20.  
  21.         TreeMap<Double, Integer> counts = new TreeMap<>();
  22.  
  23.         for (Double num : nums) {
  24.             if (!counts.containsKey(num)) {
  25.                 counts.put(num, 0);
  26.             }
  27.             counts.put(num, counts.get(num) + 1);
  28.         }
  29.         for (Map.Entry<Double, Integer> entry : counts.entrySet()) {
  30.             System.out.printf("%.0f -> %d%n", entry.getKey(), entry.getValue());
  31.         }
  32.  
  33.  
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement