-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hashmap5.java
46 lines (38 loc) · 1.09 KB
/
Hashmap5.java
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
38
39
40
41
42
43
44
45
46
import java.util.*;
public class Hashmap5
{
public static void main(String[] Google)
{
Scanner sobj = new Scanner(System.in);
System.out.println("Enter String : ");
String str = sobj.nextLine();
str = str.replaceAll(" ","");
char Arr[] = str.toCharArray();
HashMap <Character, Integer> hobj = new HashMap<Character, Integer>();
int Frequency = 0;
for(char ch : Arr)
{
if(hobj.containsKey(ch))
{
Frequency = hobj.get(ch);
hobj.put(ch, Frequency+1);
}
else
{
hobj.put(ch,1);
}
}
Set <Character> setobj = hobj.keySet();
int iMax = 0;
char ch = '\0';
for(char data : setobj)
{
if(hobj.get(data) > iMax)
{
iMax = hobj.get(data);
ch = data;
}
}
System.out.println(ch + " occurs maximum numeber of times in string i.e " + iMax+" times");
}
}