-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMostOccurance.java
More file actions
37 lines (27 loc) · 802 Bytes
/
Copy pathMostOccurance.java
File metadata and controls
37 lines (27 loc) · 802 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
26
27
28
29
30
31
32
33
34
35
36
37
package practice;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class MostOccurance {
public static String printResult(String str) {
String result = "";
Map<Character, Integer> res = new HashMap<>();
char[] arr = str.toCharArray();
Arrays.sort(arr);
for(int i= 0 ;i<arr.length;i++) {
if(res.containsKey(i)) {
res.put(arr[i], res.get(i)+1);
}
else
res.put(arr[i], 1);
System.out.println(res);
}
return result;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.next();
System.out.println(printResult(str));
}
}