-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountSymbols.java
More file actions
25 lines (23 loc) · 847 Bytes
/
Copy pathCountSymbols.java
File metadata and controls
25 lines (23 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package Exercises;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class CountSymbols {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String input = scan.nextLine();
Map<Character,Integer> elements = new TreeMap();
int count = 0;
for (char symbol : input.toCharArray()) {
if (!elements.containsKey(symbol)) {
elements.put(symbol, 1);
} else {
int numOfRepetition = elements.get(symbol);
elements.put(symbol, numOfRepetition + 1);
}
}
for(Map.Entry<Character, Integer> pair : elements.entrySet()){
System.out.println(String.format("%s: %d time/s",pair.getKey(),pair.getValue()));
}
}
}