-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunique_value_array.java
More file actions
56 lines (55 loc) · 1023 Bytes
/
unique_value_array.java
File metadata and controls
56 lines (55 loc) · 1023 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.Scanner;
class unique_value_array{
public static void main(String args[]){
Scanner sc= new Scanner(System.in);
System.out.println("Enter no. of elements: ");
int size=sc.nextInt();
int arr[]=new int[size];
for(int i=0; i<arr.length; i++){
arr[i]=sc.nextInt();
}
int distinct = 0;
for(int i=0; i<arr.length; i++){
for(int j=0; j<=i; j++){
if(i==j){
distinct++;
}
else if(arr[i]==arr[j]){
break;
}
}
}
int arr2[]=new int[distinct];
int index=0;
for(int i=0; i<arr.length; i++){
for(int j=0; j<=i; j++){
if(i==j){
arr2[index]=arr[i];
index++;
}
else if(arr[i]==arr[j]){
break;
}
}
}
int arr3[]=new int[distinct];
for(int i=0; i<arr2.length; i++){
int a=0;
for(int j=0; j<arr.length; j++){
if(arr2[i]==arr[j]){
a++;
}
}
arr3[i]=a;
}
boolean bool=true;
for(int i=0; i<arr3.length-1; i++){
for(int j=i+1; j<arr3.length; j++){
if(arr3[i]==arr3[j]){
bool=false;
}
}
}
System.out.println(bool);
}
}