-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArray47.java
More file actions
38 lines (34 loc) · 1015 Bytes
/
Array47.java
File metadata and controls
38 lines (34 loc) · 1015 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
37
38
package array;
/**
* Project Admin -> Husanboy Azamov
* Package Name -> array
* Class Name -> Array47
* Copyright © : 6/25/2022
*/
public class Array47 {
public static void main(String[] args) {
int[] test1 = {1,2,4,5,6,5,3,2,1,7,8,2,};
solution(test1);
}
// 7 4 2 3 1 4 5 2 4 7
// 7
public static void solution(int[] array) {
for (int i = 0; i < array.length; i++) {
int element = array[i]; // i=5; element=4
boolean mavjud = false; //
for (int j = 0; j < i; j++) {
mavjud = mavjud || element == array[j];
}
if (!mavjud) {
System.out.println(element + " soni " + counter(element, array) + " ta");
}// 7 4 2 3 1
}
}
public static int counter(int element, int[] array) {
int counter = 0;
for (int j = 0; j < array.length; j++) {
if (element == array[j]) counter++;
}
return counter;
}
}