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