-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduplicatechar.java
More file actions
36 lines (32 loc) · 953 Bytes
/
Copy pathduplicatechar.java
File metadata and controls
36 lines (32 loc) · 953 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
package Strings;
import java.util.Scanner;
import java.util.Arrays;
public class duplicatechar {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String str;
int count = 1;
System.out.println("enter the string : ");
str = s.nextLine();
int l = str.length();
int arr[] = new int[l];
char c[] = str.toCharArray();
Arrays.sort(c);
for (int i = 0; i < l; i++) {
System.out.print(c[i]);
}
System.out.println();
for (int i = 0; i < l-1; i++) {
if (c[i] == c[i + 1]) {
count++;
} else {
if(count>=2)
{
System.out.println("Count: " + count);
}
count = 1;
}
}
System.out.println("Count: " + count);
}
}