-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion12.java
More file actions
39 lines (36 loc) · 1.07 KB
/
question12.java
File metadata and controls
39 lines (36 loc) · 1.07 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
39
public class question12{
public static void main(String[] args) {
int arr[] = {1,2,4,1,6,7,5};
int n =arr.length;
int count = 0;
int i = 0;
int j = 0;
int k = 0;
int[] temp = new int[n];
for (i = 0; i < n; i++){
count = 1;
for (j = i + 1; j < n; j++){
if (arr[i] == arr[j]){
count++;
temp[j] = -1;
}
}
if (temp[i] != -1){
temp[i] = count;
}
}
System.out.println("the occurence of each element in the array is:");
for (i = 0; i < n; i++) {
if (temp[i] != -1){
System.out.println(arr[i] + " occurs " + temp[i]+ "time");
}
}
System.out.println("the unique elemts in the array are:");
for (i= 0; i < n; i++) {
if (temp[i] != -1) {
System.out.println(arr[i] + " ");
}
}
System.out.println();
}
}