Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String text = scanner.nextLine();
- Map<Character, Integer> table = new LinkedHashMap<>();
- for (char symbol : text.toCharArray()) {
- if (symbol != ' ') {
- if (!table.containsKey(symbol)) {
- table.put(symbol, 1);
- } else {
- int currentCount = table.get(symbol);
- table.put(symbol, currentCount + 1);
- }
- }
- }
- for (Map.Entry<Character, Integer> entry : table.entrySet()) {
- System.out.printf("%c -> %d%n", entry.getKey(), entry.getValue());
- }
- }
- }
Add Comment
Please, Sign In to add comment