-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxFrequency.java
More file actions
31 lines (26 loc) · 836 Bytes
/
MaxFrequency.java
File metadata and controls
31 lines (26 loc) · 836 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
import java.util.HashMap;
import java.util.Scanner;
public class MaxFrequency {
public static void main(String[] args) {
System.out.println(" write string here ");
Scanner scn =new Scanner(System.in);
String str =scn.nextLine();
int i=0;
int mf=1;
HashMap<Character,Integer> map = new HashMap<>();
for(i=0;i<str.length();i++){
char ch =str.charAt(i);
if(map.containsKey(ch)){
int prevf = map.get(ch);
int newf = prevf+1;
map.put(ch,newf);
}else
map.put(ch,1);
}
for(Character key :map.keySet()){
if(map.get(key)>map.get(str.charAt(0)))
mf=map.get(key);
}
System.out.println(mf);
}
}