Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lekciq;
- import java.util.LinkedHashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class CountRealNumbers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- String[] numbers = input.split(" ");
- // Map to store the count of each number
- Map<Double, Integer> countMap = new LinkedHashMap<>();
- // Iterate over the numbers array and count occurrences
- for (String number : numbers) {
- double num = Double.parseDouble(number);
- countMap.put(num, countMap.getOrDefault(num, 0) + 1);
- }
- // Print the result
- for (Map.Entry<Double, Integer> entry : countMap.entrySet()) {
- double num = entry.getKey();
- int count = entry.getValue();
- System.out.printf("%.1f -> %d\n", num, count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement