-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirst_Half.java
More file actions
44 lines (33 loc) · 914 Bytes
/
First_Half.java
File metadata and controls
44 lines (33 loc) · 914 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
import java.util.ArrayList;
import java.util.Random;
public class First_Half implements Runnable{
private volatile ArrayList<Integer> Array = new ArrayList<>();
private int range;
First_Half(int range){
this.range = range;
}
@Override
public void run() {
Random value = new Random();
int Count = 0;
while( Count < range ){
int temp = value.nextInt(range);
if(is_Unique(Array, Count, temp)){
Array.add(temp);
Count++;
}
}
System.out.println("Thread 1 Complete");
}
boolean is_Unique(ArrayList<Integer> Array, int Size, int val){
for(int i=0; i<Size; i++){
if(Array.get(i) == val ){
return false;
}
}
return true;
}
public ArrayList<Integer> get_Array(){
return Array;
}
}