-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeats.java
More file actions
38 lines (35 loc) · 1.14 KB
/
repeats.java
File metadata and controls
38 lines (35 loc) · 1.14 KB
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
public class repeats {
static boolean isFind(int[] arr, int value){
for (int i : arr) {
if(i == value){
return true;
}
}
return false;
}
public static void main(String[] args) {
int arr[] = {1,3,41,2,3,41,51,1,1,2,6,15,6,3,3,2};
int dublicates[] = new int[arr.length];
int startingIndex = 0;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
if((i != j) && (arr[i] == arr[j])){
if(!isFind(dublicates, arr[i])){
dublicates[startingIndex++] = arr[i];
}
break;
}
}
}
for (int i = 0; i < dublicates.length; i++) {
int counter = 0;
for (int j = 0; j < arr.length; j++) {
if(dublicates[i] == arr[j]){
counter++;
}
}
if(dublicates[i] != 0)
System.out.println(dublicates[i]+" repeted "+ counter +" times");
}
}
}