Advertisement
deyanmalinov

01. Count Real Numbers

Mar 15th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. package DPM;
  2. import java.text.DecimalFormat;
  3. import java.util.*;
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.         double [] nums = Arrays.stream(scan.nextLine().split(" ")).mapToDouble(Double::parseDouble).toArray();
  8.  
  9.         Map<Double, Integer> newMap = new TreeMap<>();
  10.  
  11.         for (double num : nums) {
  12.             if (!newMap.containsKey(num)){
  13.                 newMap.put(num, 0);
  14.             }
  15.             newMap.put(num, newMap.get(num)+1);
  16.         }
  17.         for (Map.Entry<Double, Integer> entry : newMap.entrySet()) {
  18.             DecimalFormat df = new DecimalFormat("#.#######");
  19.             System.out.printf("%s -> %d%n", df.format(entry.getKey()), entry.getValue());
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement