-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathProblem_3.java
More file actions
32 lines (25 loc) · 908 Bytes
/
Problem_3.java
File metadata and controls
32 lines (25 loc) · 908 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
package strings;
import java.util.Scanner;
//* Problem Title ==> Find Duplicate characters in a string
public class Problem_3 {
static final int NO_OF_CHARS = 256;
// Fills count array with frequency of characters
static void fillCharCounts(String str, int[] count) {
for (int i = 0; i < str.length(); i++)
count[str.charAt(i)]++;
}
static void printDups(String str) {
// Create an array of size 256 and fill count of every character in it
int[] count = new int[NO_OF_CHARS];
fillCharCounts(str, count);
for (int i = 0; i < NO_OF_CHARS; i++)
if (count[i] > 1)
System.out.println((char) (i) + ", count = " + count[i]);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
printDups(str);
sc.close();
}
}