-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram505.java
More file actions
40 lines (31 loc) · 943 Bytes
/
Copy pathprogram505.java
File metadata and controls
40 lines (31 loc) · 943 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
38
39
40
import java.util.*;
public class program505
{
public static void main(String[] args)
{
Scanner sobj = new Scanner(System.in);
System.out.println("Enter The String : ");
String str = sobj.nextLine();
str = str.replaceAll(" ", "");
HashMap <Character, Integer>hobj = new HashMap<Character,Integer>();
char Arr[] = str.toCharArray();
int Frequency = 0;
for(char ch : Arr)
{
if(hobj.containsKey(ch)) // Character is already there in hashmap
{
Frequency = hobj.get(ch);
hobj.put(ch,Frequency+1);
}
else // Character occured first time
{
hobj.put(ch,1);
}
}
System.out.println("Unique Character are :");
for(char ch : hobj.keySet())
{
System.out.println(ch);
}
}
}