deyanmalinov

04. Count Real Numbers

May 28th, 2019
132
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package DPM;
  2.  
  3. import java.util.Arrays;
  4. import java.util.LinkedHashMap;
  5. import java.util.Scanner;
  6. public class Main {
  7.     public static void main(String[] args){
  8.         Scanner scan = new Scanner(System.in);
  9.         double [] nums = Arrays.stream(scan.nextLine().split(" ")).mapToDouble(Double::parseDouble).toArray();
  10.         LinkedHashMap<Double, Integer> sets = new LinkedHashMap<>();
  11.         for (int i = 0; i < nums.length; i++) {
  12.             if (sets.containsKey(nums[i])){
  13.                 sets.put(nums[i], sets.get(nums[i])+1);
  14.             }else {
  15.                 sets.put(nums[i], 1);
  16.             }
  17.         }
  18.         for (Double aDouble : sets.keySet()) {
  19.             System.out.printf("%.1f -> %d", aDouble, sets.get(aDouble));
  20.             System.out.println();
  21.         }
  22.     }
  23. }
RAW Paste Data