forked from iamshubhamg/Leet-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Count_Repetative.java
44 lines (40 loc) · 949 Bytes
/
Count_Repetative.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
import java.io.*;
public class Main
{
static BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
static String input()throws IOException
{
String S=br.readLine();
return S;
}
static int[] counter(String S)
{
int count[]=new int[256];
for(int i=0;i<256;i++)
{
count[i]=0;
}
for(int i=0;i<S.length();i++)
{
count[S.charAt(i)]++;
}
return count;
}
static void findDuplicates(String S)
{
int A[]=counter(S);
for(int i=0;i<256;i++)
{
if(A[i]>1)
{
System.out.println((char)(i)+" appears "+A[i]+" times");
}
}
}
public static void main(String[] args)throws IOException
{
Main obj = new Main();
String Str=obj.input();
obj.findDuplicates(Str);
}
}