- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeats.java
More file actions
Latest commit
38 lines (35 loc) · 1.14 KB
/
Copy pathrepeats.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
publicclassrepeats {
staticbooleanisFind(int[] arr, intvalue){
for (inti : arr) {
if(i == value){
returntrue;
}
}
returnfalse;
}
publicstaticvoidmain(String[] args) {
intarr[] = {1,3,41,2,3,41,51,1,1,2,6,15,6,3,3,2};
intdublicates[] = newint[arr.length];
intstartingIndex = 0;
for (inti = 0; i < arr.length; i++) {
for (intj = 0; j < arr.length; j++) {
if((i != j) && (arr[i] == arr[j])){
if(!isFind(dublicates, arr[i])){
dublicates[startingIndex++] = arr[i];
}
break;
}
}
}
for (inti = 0; i < dublicates.length; i++) {
intcounter = 0;
for (intj = 0; j < arr.length; j++) {
if(dublicates[i] == arr[j]){
counter++;
}
}
if(dublicates[i] != 0)
System.out.println(dublicates[i]+" repeted "+ counter +" times");
}
}
}